Keyboard Events
Dave Cragg
dcragg at lacscentre.co.uk
Tue Jul 30 10:32:01 EDT 2002
At 10:51 am -0400 30/7/02, Simtech Publications wrote:
>Hello All:
>
>I'm still struggling trying to get out of my Director/Lingo habits. I'm
>trying to intercept simple keyboard events but I'm having problems. This
>project is a simple slideshow that advances card by card using the spacebar.
>So far this works fine...
>
>on rawkeydown thekey
> if thekey = space then
> play "beep1"
> go next
> end if
>end rawkeydown
>
>However, I need to prevent the slideshow from "running away" if the user
>holds the spacebar down. In Director this works...
>
>repeat while the keypressed = " "
>end repeat
Setting a flag when the key is first depressed is one way to handle this.
local lcSpaceDown
on rawkeydown thekey
if thekey = space then
if not lcSpaceDown then
put true into lcSpaceDown
play "beep1"
go next
end if
else
pass rawkeydown
end if
end rawkeydown
on rawKeyUp thekey
if thekey = space then
put false into lcSpaceDown
else
pass rawKeyUp
end if
end rawKeyUp
>Transcript doesn't like that. Any suggestions on how to bring things to a
>halt until the spacebar is released?
>
>Also, I want the user to be able to go back to the main menu by pressing the
>control key at any time during the slideshow. I tried doing this in an idle
>handler in the card script as follows...
>
>on idle
> if the controlkey is down then go to cd "main menu"
>end idle
>
>This only works inconsistently. I can't explain why. Can anyone help?
How about using a different key, Escape for example? Then you can
catch it in a rawkeydown handler in the card or stack script. The
Control/Alt/Option/Command keys are not captured in rawKeyDown
events, I guess as they are intended to be used with other keys. (But
it would be nice sometimes.)
Cheers
Dave
More information about the use-livecode
mailing list