User Guide
332
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.
Examples
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
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"
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
keyCode(), key()
on keyUp
Syntax
on keyUp
statement(s)
end
Description
System message and event handler; contains statements that run when a key is released. The on
keyUp
handler is similar to the on keyDown handler, except this event occurs after a character
appears if a field or text sprite is editable on the screen.