Keyboard Keys and Key Code Values
Keyboard Keys and Key Code Values
The following tables list all the keys on a standard keyboard and the corresponding key code values and ASCII key code values that are used to identify the keys in ActionScript: You can use key constants to intercept the built-in behavior of keypresses. For more information on the on() handler, see on handler in the ActionScript 2.0 Language Reference. To capture key code values and ASCII key code values using a SWF file and key presses, draw a text field on the Stage. Select Input Text from the Text Type drop-down menu in the Properties panel, and click the Show border around text option. Then paste the following ActionScript code into the actions panel for the current Frame on the Timeline: var keyListener:Object = new Object();
keyListener.onKeyDown = function() { trace("DOWN -> Code: " + Key.getCode() + "\tACSII: " + Key.getAscii() + "\tKey: " + chr(Key.getAscii())); }; Key.addListener(keyListener);
For more information on the Key class, see Key in ActionScript 2.0 Language Reference. To trap keys when you test a SWF file in the authoring environment (Control > Test Movie), make sure that you select Control > Disable Keyboard Shortcuts.
K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 a b c d e
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 48 49 50 51 52 53 54 55 56 57 65 66 67 68 69
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 48 49 50 51 52 53 54 55 56 57 97 98 99 100 101
f g h i j k l m n o p q r s t u v w x y z
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
Numpad 6 Numpad 7 Numpad 8 Numpad 9 Multiply Add Enter Subtract Decimal Divide
54 55 56 57 42 43 13 45 46 47
Function keys
The following table lists the function keys on a standard keyboard, with the corresponding key code values that are used to identify the keys in ActionScript: Function key F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 112 113 114 115 116 117 118 119 120 This key is reserved by the system and cannot be used in ActionScript. 122 123 124 125 126 Key code 0 0 0 0 0 0 0 0 0 This key is reserved by the system and cannot be used in ActionScript. 0 0 0 0 0 ASCII key code
Other keys
The following table lists keys on a standard keyboard other than letters, numbers, numeric keypad keys, or function keys, with the corresponding key code values that are used to identify the keys in ActionScript: Key Backspace Tab Enter Shift Control Caps Lock Esc Spacebar Page Up Page Down End Home Left Arrow Up Arrow Right Arrow Down Arrow Insert Delete Num Lock ScrLk Pause/Break ;: =+ -_ /? `~ [{ \| ]} Key code 8 9 13 16 17 20 27 32 33 34 35 36 37 38 39 40 45 46 144 145 19 186 187 189 191 192 219 220 221 ASCII key code 8 9 13 0 0 0 27 32 0 0 0 0 0 0 0 0 0 127 0 0 0 59 61 45 47 96 91 92 93
"' , . /
39 44 46 47
For additional key code and ASCII values, use the ActionScript at the beginning of this appendix and press the desired key to trace its key code.