# Recording reaction time and response key in a trial

**URL:** <https://psychtoolbox.discourse.group/t/recording-reaction-time-and-response-key-in-a-trial/2047>\
**Category:** Uncategorized\
**Created:** [January 27, 2009, 1:32pm UTC](https://psychtoolbox.discourse.group/t/recording-reaction-time-and-response-key-in-a-trial/2047 "2009-01-27T13:32:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre.bordaberry](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@pierre.bordaberry](https://psychtoolbox.discourse.group/u/pierre.bordaberry)\
**Post date:** [January 27, 2009, 1:32pm UTC](https://psychtoolbox.discourse.group/t/recording-reaction-time-and-response-key-in-a-trial/2047/1 "2009-01-27T13:32:01Z")

</div>

hi, i'm a beginner building an experiment with PTB3. I tried to record   
reaction time and response key during a trial of 4 sec (fixed limit)   
but all i managed to do is to switch to the next trial when a key is   
pressed. I can have my RT and RK but only if my trial stop when a   
response came. As a trial have to last 4 sec, i'm a bit lost. If   
someone have an idea, i would appreciate. Thanks.  
  
Here's my code:  
  
Screen('DrawTexture',whichscreen,wa2);  
Screen(whichscreen,'flip');  
FinP=GetSecs+(1/f)\*round(4\*f);  
 while GetSecs\<FinP   
 while (~keycode(Toucherep1))& (~keycode(Toucherep2))  
 [keyisdown,secs,keycode]= KbCheck;  
 answer=KbName(keycode)  
 if GetSecs\<FinP, break, end  
 end  
 end

---

<div class="post-metadata">

**Author:** ![pierre.bordaberry](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@pierre.bordaberry](https://psychtoolbox.discourse.group/u/pierre.bordaberry)\
**Post date:** [January 28, 2009, 3:12pm UTC](https://psychtoolbox.discourse.group/t/recording-reaction-time-and-response-key-in-a-trial/2047/2 "2009-01-28T15:12:32Z")

</div>

Thanks for your answer. Help me a lot.  
Pierre.  
--- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "Mario Kleiner"   
\<mario.kleiner@...\> wrote:  

> \>  
> \> E.g.:  
> \>   
> \> answer = [];  
> \> Screen('DrawTexture',whichscreen,wa2);  
> \> tonset = Screen(whichscreen,'flip');  
> \> FinP=tonset+(1/f)\*round(4\*f);  
> \> while GetSecs\<FinP   
> \> if isempty(answer)  
> \> [keyisdown,secs,keycode]= KbCheck;  
> \> if keycode(Toucherep1) || keycode(Toucherep2)  
> \> answer=KbName(min(find(keycode)));  
> \> resptime = secs - tonset;  
> \> end  
> \> end  
> \> end  
> \>   
> \> -\> min(find... to disambiguate if subject  
> \> manages to press multiple keys at the same time.  
> \>   
> \> -\> Have a look at the timestamps returned and  
> \> accepted by Screen('Flip') for more precise control  
> \> of timing.  
> \>   
> \> -\> secs from KbCheck is the best approximation  
> \> to a response time you can get from the keyboard.  
> \> Also interesting is help KbCheck for the optional  
> \> 'deltaSecs' return argument.  
> \>   
> \> -\> Keyboards are only good for coarse RT  
> \> measurements, but we had this discussion  
> \> already a couple of times on the forum...  
> \>   
> \> -mario  
> \>   
> \>   
> \> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "pierre.bordaberry@"

\<pierre.bordaberry@\>   

> \> wrote:  
> \> \>  
> \> \> hi, i'm a beginner building an experiment with PTB3. I tried to

record   

> \> \> reaction time and response key during a trial of 4 sec (fixed

limit)   

> \> \> but all i managed to do is to switch to the next trial when a key

is   

> \> \> pressed. I can have my RT and RK but only if my trial stop when a   
> \> \> response came. As a trial have to last 4 sec, i'm a bit lost. If   
> \> \> someone have an idea, i would appreciate. Thanks.  
> \> \>   
> \> \> Here's my code:  
> \> \>   
> \> \> Screen('DrawTexture',whichscreen,wa2);  
> \> \> Screen(whichscreen,'flip');  
> \> \> FinP=GetSecs+(1/f)\*round(4\*f);  
> \> \> while GetSecs\<FinP   
> \> \> while (~keycode(Toucherep1))& (~keycode(Toucherep2))  
> \> \> [keyisdown,secs,keycode]= KbCheck;  
> \> \> answer=KbName(keycode)  
> \> \> if GetSecs\<FinP, break, end  
> \> \> end  
> \> \> end  
> \> \>  
> \>
