Lingo Dictionary > G-K > keyPressed() |
![]() ![]() ![]() |
keyPressed()
Syntax
the keyPressed
keyPressed (keyCode
) keyPressed (asciiCharacterString)
Description
Function; returns the character assigned to the key that was last pressed if no argument is used. The result is in the form of a string. When no key has been pressed, the keyPressed
is an empty string.
If an argument is used, either a keyCode or the ASCII string for the key being pressed may be used. In either of these cases, the return value is TRUE
if that particular key is being pressed, or FALSE
if not.
The Director player for Java doesn't support this property. As a result, a movie playing back as an applet has no way to detect which key the user pressed while Lingo is in a repeat loop.
The keyPressed
property is updated when the user presses keys while Lingo is in a repeat loop. This is an advantage over the key
function, which doesn't update when Lingo is in a repeat loop.
Use the sample movie Keyboard Lingo to test which characters correspond to different keys on different keyboards.
This property can be tested but not set.
Example
The following statement checks whether the user pressed the Enter key in Windows or the Return key on a Macintosh and runs the handler updateData
if the key was pressed:
if the keyPressed = RETURN then updateData
Example
This statement uses the keyCode for the a key to test if it's down, and displays the result in the Message window:
if keyPressed(0) then put "Key is down"
Example
This statement uses the ASCII strings to test if the a and b keys are down, and displays the result in the Message window:
if keyPressed("a") and keyPressed ("b") then put "Keys are down"
See also
![]() ![]() ![]() |