Adding Key down handler for Application
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
import mx.core.Application ;
import flash.events.KeyboardEvent;
import mx.controls.Alert;
private function init():void
{
this.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler );
}
private function keyHandler (e:KeyboardEvent):void
{
txt_code.text = String(e.keyCode);
txt_char.text = String(e.charCode);
}
</mx:Script>
<mx:HBox>
<mx:Label text="KeyCode Pressed"/>
<mx:Label text="Charcode :"/>
<mx:TextInput id="txt_char"/>
<mx:TextInput id="txt_code"/>
</mx:HBox>
</mx:Application>
Related examples in the same category