Wait for keyDown response

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
starfirescully
Posts: 23
Joined: Wed Jul 09, 2014 2:35 pm

Wait for keyDown response

Post by starfirescully » Mon Dec 19, 2016 9:26 pm

I am trying to create a reaction time experiment.
Right now I have a button that begins the experiment, coded to display a fixation cross, picture, and word.
I have codes that control what each keyDown response does on the card.
After the button displays the word, I would like it to wait to continue until a keyDown response has been recorded. Is there a way to do this?

Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: Wait for keyDown response

Post by dunbarx » Mon Dec 19, 2016 10:11 pm

Hi.

Not sure I see the problem. Yet.

1- You show several objects, as you say. Finished, done.
2- Then you want the user to press a key that does something. Certain keys are handled, I assume in a keyDown (or up) handler in the card script. Or wherever.

So the system is already "waiting" if you see what I mean. That is, the keydown message is a separate event, independent of anything that went before. There is no process "wait" required in this case; I see no connection between the two.

Or do I have this wrong?

Craig Newman

starfirescully
Posts: 23
Joined: Wed Jul 09, 2014 2:35 pm

Re: Wait for keyDown response

Post by starfirescully » Mon Dec 19, 2016 10:27 pm

Craig,

That makes sense! I managed to fix the issue. This originally didn't work because I had the "waiting" within a repeat loop, so it didn't actually wait.

Thanks!

starfirescully
Posts: 23
Joined: Wed Jul 09, 2014 2:35 pm

Re: Wait for keyDown response

Post by starfirescully » Mon Dec 19, 2016 10:31 pm

Now I just have to figure out how to make sure only the specific keys work, and no others.

Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: Wait for keyDown response

Post by dunbarx » Mon Dec 19, 2016 10:44 pm

Good going.

The "keyDown" message takes a single parameter. You would do something like:

Code: Select all

on keyDown tKey
  if tKey = thisKey then doSomething
  if tKey = thatKey then doSomethingElse
end keyDown
This will only process the keys you are interested in. But be careful, you will have trapped a very important message. If this is in the card script, for example, you will not be able to type into a field. Can you make the above handler more robust on your own? If so, fine. If not, look up the "pass" control structure before asking here.

Craig

Post Reply