I'm building a Flex application and I need to define a keyboard (keyDown) handler that is global to the entire application. It should see every keypress, no matter what item has focus, and it should be able to optionally prevent that keypress from being propagated throughout the display list.

The reason for this is that I'm implementing application-level keyboard shortcuts, as well as support for a credit card swiper (which acts like a keyboard, rapidly entering the data from the card) in a point of sale application. No matter what text field has focus, the keypresses entered by the swiper should never show up, and should be handled by an invisible process.

I've tried attaching a keyDown handler to the stage and then using event.stopImmediatePropagation() but it has no effect, and bizarrely, AS3 doesn't allow preventDefault() on keyDown and keyUp events. Coming from JavaScript, where you CAN prevent the default behavior on those events, this seems like a silly and arbitrary limitation.