Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > Key > onKeyDown (Key.onKeyDown event listener) | |||
onKeyDown = function() {}
Notified when a key is pressed. To use onKeyDown, you must create a listener object. You can then define a function for onKeyDown and use addListener() to register the listener with the Key object, as shown in the following example:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("DOWN -> Code: "+Key.getCode()+"\tASCII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
};
keyListener.onKeyUp = function() {
trace("UP -> Code: "+Key.getCode()+"\tASCII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
};
Key.addListener(keyListener);
Listeners enable different pieces of code to cooperate because multiple listeners can receive notification about a single event.
A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
Availability: ActionScript 1.0; Flash Player 6
addListener (Key.addListener method)
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001767.html