Trapping key presses outside fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Trapping key presses outside fields
I am trying to capture a key press after a card opens. There is no field on the card - just an image - and I am interested in how long it takes for someone to press a key after the card opens. It's a psychological experiment. I've tried the various handlers for key presses, but they seem to function only for key presses within fields - I could be wrong. Any suggestions greatly appreciated.
Thanks
Cyril
Thanks
Cyril
Re: Trapping key presses outside fields
Hi Cyril,
Probably, you want to use the rawKeyDown or rawKeyUp message.
Best,
Mark
Probably, you want to use the rawKeyDown or rawKeyUp message.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Trapping key presses outside fields
Thanks Mark,
Yes, I've tried rawKeyDown without success. Even the key relevant sample scripts from the Manual don't work.
Cheers
Cyril
Yes, I've tried rawKeyDown without success. Even the key relevant sample scripts from the Manual don't work.
Cheers
Cyril
Re: Trapping key presses outside fields
Cyril,
I assure you that those handlers work in fields, cards and stacks.
Best,
Mark
I assure you that those handlers work in fields, cards and stacks.
Code: Select all
on rawkeyup
beep
pass rawkeyup
end rawkeyup
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Trapping key presses outside fields
I’ve found there’s a slight trick when dealing with images. rawKeyDown is sent to the control with the “focus”, i.e. its traversalOn property is set to true. You can get an image to respond to rawKeyDown/Up by:
... either in the message box or in a handler. The Property Inspector for images doesn’t let you set this directly, but I’ve found it can be set. What may work better for you is to put the rawKeyDown/Up handler in the card, or stack, script, especially if you are navigating from card to card. You could try the following in the stack script:
... this should show the duration in milliseconds between the openCard and the next keypress in the message box. There is no need to set the traversalOn for the individual images in this case.
Regards,
Michael
Code: Select all
set the traversalOn of image “MyImageName” to true
Code: Select all
global openTime, measureTime
on openCard
put "Yes" into measureTime
put the milliseconds into openTime
pass opencard
end openCard
on rawKeyDown
if measureTime = "Yes" then
put the milliseconds into pressTime
put pressTime - openTime
put "No" into measureTime
end if
pass rawKeyDown
end rawKeyDown
Regards,
Michael
Re: Trapping key presses outside fields
Thanks Mark, you are of course right.Mark wrote:Cyril,
I assure you that those handlers work in fields, cards and stacks.
Best,Code: Select all
on rawkeyup beep pass rawkeyup end rawkeyup
Mark
Cyril
Re: Trapping key presses outside fields
Code: Select all
global openTime, measureTime
on openCard
put "Yes" into measureTime
put the milliseconds into openTime
pass opencard
end openCard
on rawKeyDown
if measureTime = "Yes" then
put the milliseconds into pressTime
put pressTime - openTime
put "No" into measureTime
end if
pass rawKeyDown
end rawKeyDown
Regards,
Michael[/quote]
Thanks Michael, Your code works a treat! Problem solved. Looking at yours and Mark's code, one of my problems may have been not passing rawKeyDown.
Cheers
Cyril