Key Code Class for Actionscript 3

March 3, 2012

Just a quickie for today.

It’s pretty trivial to write a keyboard handler in AS3. However, I found it more annoying to simply create a nice complete keycode class where I can refer to all the keys by named constants.

There are one or two pages with the info (with some minor errors), but it’s not in a very convenient format. Therefore, I give you the Keys class for your convenience:

package
{
public class Keys
{
static public const BACKSPACE:uint = 8;
static public const TAB:uint = 9;

static public const ENTER:uint = 13;
static public const SHIFT:uint = 16;
static public const CONTROL:uint = 17;
static public const ALT:uint = 18;
static public const PAUSE:uint = 19;
static public const CAPS_LOCK:uint = 20;

static public const ESCAPE:uint = 27;

static public const SPACE:uint = 32;
static public const PAGE_UP:uint = 33;
static public const PAGE_DOWN:uint = 34;
static public const END:uint = 35;
static public const HOME:uint = 36;
static public const LEFT:uint = 37;
static public const UP:uint = 38;
static public const RIGHT:uint = 39;
static public const DOWN:uint = 40;

static public const INSERT:uint = 45;
static public const DELETE:uint = 46;

static public const ZERO:uint = 48;
static public const ONE:uint = 49;
static public const TWO:uint = 50;
static public const THREE:uint = 51;
static public const FOUR:uint = 52;
static public const FIVE:uint = 53;
static public const SIX:uint = 54;
static public const SEVEN:uint = 55;
static public const EIGHT:uint = 56;
static public const NINE:uint = 57;

static public const A:uint = 65;
static public const B:uint = 66;
static public const C:uint = 67;
static public const D:uint = 68;
static public const E:uint = 69;
static public const F:uint = 70;
static public const G:uint = 71;
static public const H:uint = 72;
static public const I:uint = 73;
static public const J:uint = 74;
static public const K:uint = 75;
static public const L:uint = 76;
static public const M:uint = 77;
static public const N:uint = 78;
static public const O:uint = 79;
static public const P:uint = 80;
static public const Q:uint = 81;
static public const R:uint = 82;
static public const S:uint = 83;
static public const T:uint = 84;
static public const U:uint = 85;
static public const V:uint = 86;
static public const W:uint = 87;
static public const X:uint = 88;
static public const Y:uint = 89;
static public const Z:uint = 90;

static public const NUM_0:uint = 96;
static public const NUM_1:uint = 97;
static public const NUM_2:uint = 98;
static public const NUM_3:uint = 99;
static public const NUM_4:uint = 100;
static public const NUM_5:uint = 101;
static public const NUM_6:uint = 102;
static public const NUM_7:uint = 103;
static public const NUM_8:uint = 104;
static public const NUM_9:uint = 105;
static public const NUM_MULTIPLY:uint = 106;
static public const NUM_ADD:uint = 107;

static public const NUM_MINUS:uint = 109;
static public const NUM_PERIOD:uint = 110;
static public const NUM_SLASH:uint = 111;
static public const F1:uint = 112;
static public const F2:uint = 113;
static public const F3:uint = 114;
static public const F4:uint = 115;
static public const F5:uint = 116;
static public const F6:uint = 117;
static public const F7:uint = 118;
static public const F8:uint = 119;
static public const F9:uint = 120;
static public const F10:uint = 121;
static public const F11:uint = 122;
static public const F12:uint = 123;
static public const F13:uint = 124;
static public const F14:uint = 125;
static public const F15:uint = 126;

static public const NUM_LOCK:uint = 144;
static public const SCROLL_LOCK:uint = 145;

static public const SEMICOLON:uint = 186;
static public const PLUS:uint = 187;
static public const COMMA:uint = 188;
static public const MINUS:uint = 189;
static public const PERIOD:uint = 190;
static public const SLASH:uint = 191;
static public const TILDE:uint = 192;

static public const LEFT_BRACKET:uint = 219;
static public const BACKSLASH:uint = 220;
static public const RIGHT_BRACKET:uint = 221;
static public const QUOTE:uint = 222;



// This class should not be instantiated, just use it's static members
public function Keys()
{
}
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: