User Guide

820 Chapter 14: Properties
See also
Movie
keyCode
Usage
-- Lingo syntax
_key.keyCode
// JavaScript syntax
_key.keyCode;
Description
Key property; returns the numerical code for the last key pressed. Read-only.
The returned value is the keys numerical value, not the American National Standards Institute
(ANSI) value.
You can use
keyCode to detect when the user has pressed an arrow or function key, which cannot
be specified by the
key property.
Use the sample movie Keyboard Lingo to test which characters correspond to different keys on
different keyboards.
Example
This handler uses the Message window to display the appropriate key code each time a key
is pressed:
-- Lingo syntax
on enterFrame
keyDownScript = put(_key.keyCode)
end
// JavaScript syntax
function enterFrame() {
keyDownScript = put(_key.keyCode);
}
This statement checks whether the up arrow (whose key code is 126) was pressed and if it was,
goes to the previous marker:
-- Lingo syntax
if (_key.keyCode = 126) then
_movie.goPrevious()
end if
// JavaScript syntax
if (_key.keyCode == 126) {
_movie.goPrevious();
}
This handler checks whether one of the arrow keys was pressed and if one was, responds
accordingly:
-- Lingo syntax
on keyDown
case (_key.keyCode) of
123: TurnLeft
126: GoForward