Page 1 of 1

Trapping key presses outside fields

Posted: Sun Mar 14, 2010 10:19 am
by clatimer
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

Re: Trapping key presses outside fields

Posted: Sun Mar 14, 2010 10:25 am
by Mark
Hi Cyril,

Probably, you want to use the rawKeyDown or rawKeyUp message.

Best,

Mark

Re: Trapping key presses outside fields

Posted: Sun Mar 14, 2010 11:00 am
by clatimer
Thanks Mark,

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

Posted: Sun Mar 14, 2010 11:15 am
by Mark
Cyril,

I assure you that those handlers work in fields, cards and stacks.

Code: Select all

on rawkeyup
     beep
     pass rawkeyup
end rawkeyup
Best,

Mark

Re: Trapping key presses outside fields

Posted: Sun Mar 14, 2010 11:33 am
by Regulae
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:

Code: Select all

set the traversalOn of image “MyImageName” to true
... 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:

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
... 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

Re: Trapping key presses outside fields

Posted: Mon Mar 15, 2010 12:40 am
by clatimer
Mark wrote:Cyril,

I assure you that those handlers work in fields, cards and stacks.

Code: Select all

on rawkeyup
     beep
     pass rawkeyup
end rawkeyup
Best,

Mark
Thanks Mark, you are of course right.
Cyril

Re: Trapping key presses outside fields

Posted: Mon Mar 15, 2010 12:57 am
by clatimer

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
... 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[/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