Global keyboard listening does not work
Here's a sample app that tries to listen for global keyboard events, but fails
to work. Why, I'm not sure. Is this a bug? This seems like it ought to be
pretty easy to achieve, considering how many people are going to want to do
this...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
backgroundColor="#FFFFFF"
applicationComplete="registerGlobalKeyHandler()">
<mx:Script>
<![CDATA[
public function registerGlobalKeyHandler() :void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}
public function handleKeyDown(event:KeyboardEvent) :void
{
display.text = "Key was pressed: " + event.keyCode;
}
]]>
</mx:Script>
<mx:Panel>
<mx:Canvas width="400" height="400">
<mx:Label id="display"
text="Click anywhere in the application and then press some keys." />
</mx:Canvas>
</mx:Panel>
</mx:Application>
|