Reputation: 37
I am having a hard time figuring out how the KbCheck function works and how I can use it to pause whatever my program is doing, wait for the spacebar to be pressed and then resume with the program.
KbCheck's documentations has this:
[keyIsDown, secs, keyCode, deltaSecs] = KbCheck([deviceNumber])
I know keyIsDown will constantly return 0 until the user presses any key, after which it will return 1. But, how do I use KbCheck with a while loop to do the above?
Upvotes: 0
Views: 3982
Reputation: 338
If you are planning to use KbWait()
you should definitly know that you get a time jittered reaction times. Documentation says up to 5 ms which may or may not cause you some problem during analysis.
This is what documentation says:
CAUTION: KbWait periodically checks the keyboard. After each failed check
(ie. no change in keyboard state) it will wait for 5 msecs before the
next check. This is done to reduce the load on your system, and it is
important to do so. However if you want to measure reaction times this is
clearly not what you want, as it adds up to 5 msecs extra uncertainty to
all measurements!
Take a look at the demo where it is explained:
edit KbDemo.m
Upvotes: 0
Reputation: 60070
KbCheck
just does a single check at the time you call it. I think what you want instead is KbWait
, which will stop execution of the program until it gets a key press:
[secs, keyCode, deltaSecs] = KbWait([deviceNumber][, forWhat=0][, untilTime=inf])
There are a number of keyboard-checking functions in PsychToolbox, so it might be worth checking if they're a better fit for your specific needs, e.g.:
KbPressWait
KbStrokeWait
KbReleaseWait
Upvotes: 2