Name
Key.getAscii( ) Method — returns the ASCII value of the last key pressed
Availability
Flash 5
Synopsis
Key.getAscii( )
Returns
An integer representing the ASCII value of the last key pressed.
Description
The getAscii( ) method returns the ASCII value
of the last key that was pressed. Since not all keys have an ASCII
value, getAscii( ) is normally used for
detecting letters and numbers from the Latin 1 character set (Western
European languages). Unlike getCode( ),
getAscii( ) distinguishes between upper- and
lowercase letters. But unlike getCode( ), it
cannot differentiate between two keys with the same ASCII value, such
as the 8 key on the main keyboard and the 8 key on the numeric
keypad.
To detect the pressing of specific keys relative to their physical
location on a keyboard rather than their ASCII value (such as would
be desirable when using four keys in a diamond pattern to control
game play), use getCode( ).
Example
The following example demonstrates keystroke detection for a simple
hangman word game. It uses a keyDown event
handler to identify the pressing of a key and adds that key to a list
of user guesses:
onClipEvent (keyDown) {
var lastKey = Key.getAscii( );
guessNum++;
userGuesses[guessNum] = String.fromCharCode(lastKey);
}See Also
Key.getCode( ); Appendix B,
and Section 10.11.4 in Chapter 10
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access