FAQ - How to collect responses during rapid drawing
Q: How can I collect responses while repeatedly presenting/updating visual stimuli?
A: The general principle is to use any down time between drawing the stimuli and calling Screen('Flip') to check the keyboard state. (NB: polling the keyboard is not the best way to record accurate reaction times. If accuracy matters, you should use a response box.) Sample code is below.
% Draw target, etc, then
[targetFlipStart, targetStimOnset] = Screen('Flip', wPtr);
%Set a stop time x seconds from the execution of this line and poll the keyboard/input device until then
stop = GetSecs + x;
while GetSecs < stop
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown
break; %Ends the while loop
end
WaitSecs(.01); %It is a good habit not to poll as fast as possible
end
RT = secs - targetStimOnset;
[targetFlipStart, targetStimOnset] = Screen('Flip', wPtr);
%Set a stop time x seconds from the execution of this line and poll the keyboard/input device until then
stop = GetSecs + x;
while GetSecs < stop
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown
break; %Ends the while loop
end
WaitSecs(.01); %It is a good habit not to poll as fast as possible
end
RT = secs - targetStimOnset;