How can I get reaction times

=== delete this after reading ===
Please make sure you read this post before asking for help. No one can help you unless you provide a clear description of the software environment you are using and your programming problem…
=== delete until here ===

Dear PTB community,

I’m building an experiment in PTB in which subjects need to press a specific button within a 2 second period in response to a stimulus. If they press the wrong button they would receive a “WRONG ANSWER!” feedback. If they are too slow they get a “FASTER!” feedback. I would also like to record subjects’ reaction times to each new stimulus. I tried to see if I could use KbWait to do all of that. So far I managed to get the “WRONG ANSWER FEEDBACK!” this way:

“” [secs,keys]=KbWait();
if find(keys) ~= 75
DrawFormattedText(w,‘WRONG!’,‘center’,‘center’,[1 0 0]);
Screen(‘Flip’,w);
WaitSecs(0.3); “”

So so far so good… now for the reaction time it’s another story. I initially tried to do it this way based on what I could gather from other discussions elsewhere:

“” MaxT = 2;
[secs,keys]=KbWait();
if find(secs)>MaxT
DrawFormattedText(w,‘FASTER!’,‘center’,‘center’,[1 0 0]);
Screen(‘Flip’,w);
WaitSecs(0.3); “”

There’s no error message in the script when I run it but I also do not get the “FASTER!” feedback after two seconds. Also, when checking on find(secs) to get the response times I always get the same answer = 1. So I suspect there’s something I missed about the KbWait function… could any of you enlighten me on this?

Thank you in advance!
Nic

I notice here that the KbWait() function does not seem to have the untilTime option for some reason, though the option shows up in the function description… Is it only available on some OS? I’m on Windows…

KbWait’s untilTime option works just fine. But your code fails because untilTime describes a deadline, until which KbWait waits, not a wait duration in seconds, as your code assumes. Iow. untilTime = GetSecs + 3 gives a 3 second wait.

There’s also convenience functions like KbStrokeWait, KbPressWait etc. for better clarity.

And a final catch for RT measurements: KbWait et al. wait 5 msecs between each poll of the keyboard to not overload systems. Won’t matter with regular keyboards as all other error are likely much higher than 5 msecs granularity, but if you had a high precision keyboard, it might show up. The modern KbQueue functions, e.g., KbEventGet, are the more efficient and precise way to go about that (cfe. KbQueueDemo.m).

-mario

1 Like

Hi Mario,
Thanks a lot. Meanwhile I found the tricks you describe here and they do the job indeed.
Thanks again!
Nicolas

The best way to thank me is for your lab to buy a paid support membership, as that’s both cheap and keeps the lights on for Psychtoolbox (or not so much, as too few labs contribute). → help PsychPaidSupportAndServices for info how to buy.