Recording reaction time and response key in a trial

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
Thanks for your answer. Help me a lot.
Pierre.
--- In 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, "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
> >
>