User Guide

Key 381
Example
The following example creates a new listener object and defines a function for onKeyDown.
The last line uses
addListener() to register the listener with the Key object so that it can
receive notification from the key down event and display information in the Output panel.
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.INSERT)) {
trace("You pressed the Insert key.");
}
};
Key.addListener(keyListener);
isDown (Key.isDown method)
public static isDown(code:Number) : Boolean
Returns true if the key specified in code is pressed; false otherwise.
Availability: ActionScript 1.0; Flash Lite 2.0
Parameters
code:Number - The key code value assigned to a specific key or a Key class property associated
with a specific key.
Returns
Boolean - The value true if the key specified in code is pressed; false otherwise.
Example
The following script lets the user control the location of a movie clip (car_mc):
car_mc.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._x += 10;
} else if (Key.isDown(Key.LEFT)) {
this._x -= 10;
}
};