-- keyDown script to despatch a couple of standard keyboard
-- shortcuts to some appropriate handlers
on keyDown
global gKeys
-- store the key in a variable in case the user presses another
-- while we're processing
set keyPressed = the key
-- command key shortcuts
if the commandDown then
if keyPressed = "Q" then doQuit
else if keyPressed = "S" then doSave
end if
end keyDown
For keys that have no string equivalent, eg the arrow keys, you can use the
keyCode function instead of the key.
However, keyDown handlers won't always receive all key events. If there are editable text fields onstage, they will intercept key presses before they get to frame or movie script "on keyDown" handlers. Only the keyDownScript can get these events, eg:
-- an crude keyDownScript to allow only numeric entry in
-- an editable text field
on startMovie
set the keyDownScript = "filterKeys"
end startMovie
on filterKeys
if the key < "0" or the key > "9" then dontPassEvent
end filterKeys
Key presses don't necessarily go to the stage movie, either. If the message
window is open, or any MIAWs are in front of the stage, the key events will
go to them instead and the keyDown handlers won't be invoked.
There are also cases that can't be detected with a keypress script at all. Some key combinations will be intercepted by the system without your movie ever getting a look-in. A few of these can be overridden by using the exitlock property in projectors, but others (function keys, FKEYs, Alt-Tab etc) are simply unavailable without XObject support.