Name
Key.getCode( ) Method — returns the keycode of the last key pressed
Availability
Flash 5
Synopsis
Key.getCode( )
Returns
An integer representing the keycode of the last key pressed.
Description
The getCode( )
method returns the keycode of the
last key that was pressed, which is an arbitrary number representing
the physical location of a key on the keyboard. On non-Windows
operating systems, the native keycode system is translated
automatically by Flash to the Windows equivalent, so
getCode( )
provides a cross-platform means of
referring to specific keys. The getCode( )
method can also be used to differentiate between two keys with the
same ASCII value. For example, it can differentiate between the 8 key
on the main keyboard and the 8 key on the numeric keypad, whereas
getAscii( )
cannot. However, getCode(
)
cannot differentiate between upper- and lowercase
letters (for example, A and
a use the same keycode because they are produced
using the same key).
Many common keycode values are available as properties of the
Key
object (e.g., Key.UP
,
Key.BACKSPACE
). To determine the keycode of a
particular key, see Appendix B or construct a
keycode tester as follows:
Create a new Flash document.
At frame 2 of the timeline, add a frame.
On frame 1, add the following code:
trace(Key.getCode( ));
Select Control → Test Movie.
Click the movie’s Stage.
Press a key. The key code for that key will appear in the Output window.
Example
Unlike isDown( )
, getCode(
)
is useful for creating interfaces where an individual ...
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.