MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference page 680

Actionscript 2.0 language reference
Table of Contents

Advertisement

Returns
- The key code of the last key pressed. This method returns 0 if no key was pressed or
Number
released, or if the key code is not accessible for security reasons.
Example
The following example calls the
creates a listener object named
event by calling
onKeyDown
the
object, which broadcasts the
Key
SWF file plays.
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
// compare return value of getCode() to constant
if (Key.getCode() == Key.ENTER) {
trace ("Virtual key code: "+Key.getCode()+" (ENTER key)");
}
else {
trace("Virtual key code: "+Key.getCode());
}
};
Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test
environment.
The following example adds a call to
The main difference is that
letters, and
Key.getCode()
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("For the last key typed:");
trace("\tThe Key code is: "+Key.getCode());
trace("\tThe ASCII value is: "+Key.getAscii());
trace("");
};
Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test
environment.
See also
getAscii (Key.getAscii method)
680
ActionScript classes
method any time a key is pressed. The example
getCode()
and defines a function that responds to the
keyListener
. The
Key.getCode()
onKeyDown
getAscii
Key.
getAscii
differentiates between uppercase and lowercase
Key.
()
does not.
,
isAccessible (Key.isAccessible method)
object is then registered to
keyListener
message whenever a key is pressed while the
to show how the two methods differ.
()

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents

Save PDF