Thursday, May 21, 2009

Flash AS2 - Detect Keyboard press

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.ENTER) {
trace("enter is pressed");
}
}

Key.addlistener(keyListener);

3 comments:

Anonymous said...

Thank you very much, just what I needed :3

Sean Carmody said...

The last line:
Key.addlistener(keyListener);

needs a capital letter "L" in the addListener, like this:
Key.addListener(keyListener);

rabia said...

Cherry MX Red key switches deliver smooth, linear key response with a wide actuation zone. They have the responsiveness you need for perfectly executing double and triple taps, and there’s no audible click or tactile “bump.” best mechanical keyboard under 50