Lingo Dictionary > G-K > key()

 

key()

Syntax

the key

Description

Function; indicates the last key that was pressed. This value is the American National Standards Institute (ANSI) value assigned to the key, not the numerical value.

You can use the key in handlers that perform certain actions when the user presses specific keys as shortcuts and other forms of interactivity. When used in a primary event handler, the actions you specify are the first to be executed.

Note: The value of the key isn't updated if the user presses a key while Lingo is in a repeat loop.

Use the sample movie Keyboard Lingo to test which characters correspond to different keys on different keyboards.

Example

These statements cause the movie to return to the main menu marker when the user presses the Return key. Because the keyDownScript property is set to checkKey, the on prepareMovie handler makes the on checkKey handler the first event handler executed when a key is pressed. The on checkKey handler checks whether the Return key is pressed and if it is, navigates to the main menu marker.

on prepareMovie
	the keyDownScript = "checkKey"
end prepareMovie
on checkKey
	if the key = RETURN then go to frame "Main Menu"
end

Example

This on keyDown handler checks whether the last key pressed is the Enter key and if it is, then calls the on addNumbers handler:

on keyDown
	if the key = RETURN then addNumbers
end keyDown

See also

commandDown, controlDown, keyCode(), optionDown