char and key code checker
Found this at adobe.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64a29-7fdb.html
Needed to trap key up and down presses.
handy to check keypress codes
♥0 |
Line 52 |
Modified 2011-03-26 09:11:26 |
MIT License
archived:2017-03-20 06:21:13
ActionScript3 source code
/**
* Copyright tjoen ( http://wonderfl.net/user/tjoen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9VMo
*/
<?xml version="1.0"?>
<!-- charts/ShowCharAndKeyCodes.mxml -->
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="init()"
width="650">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script><![CDATA[
import flash.events.KeyboardEvent;
private function init():void {
ti1.setFocus();
this.addEventListener(KeyboardEvent.KEY_DOWN, trapKeys);
}
private function trapKeys(e:KeyboardEvent):void {
ta1.text = String(e.toString());
l1.text = numToChar(e.charCode) + " (" + String(e.charCode) + ")";
l2.text = numToChar(e.keyCode) + " (" + String(e.keyCode) + ")";
}
private function numToChar(num:int):String {
if (num > 47 && num < 58) {
var strNums:String = "0123456789";
return strNums.charAt(num - 48);
} else if (num > 64 && num < 91) {
var strCaps:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return strCaps.charAt(num - 65);
} else if (num > 96 && num < 123) {
var strLow:String = "abcdefghijklmnopqrstuvwxyz";
return strLow.charAt(num - 97);
} else {
return num.toString();
}
}
]]></fx:Script>
<s:TextInput width="50%" id="ti1"/>
<s:Panel id="mainPanel" width="100%" height="100%">
<mx:Form>
<mx:FormItem label="Char (Code)">
<mx:Label id="l1"/>
</mx:FormItem>
<mx:FormItem label="Key (Code)">
<mx:Label id="l2"/>
</mx:FormItem>
<mx:FormItem label="Key Event">
<mx:TextArea id="ta1" width="250" height="200" editable="false"/>
</mx:FormItem>
</mx:Form>
</s:Panel>
</s:Application>