Wait for a key press or move on with next trial
4 views (last 30 days)
Show older comments
Hi, I'm using psychtoolbox to run an experiment. I need to wait for a partecipant key press. If any key is pressed after 2 seconds, move on to next trial. I have this code:
while (StimTime-starttime)<=StimTime
[KeyIsDown, endtime, KeyCode]=KbCheck;
if KeyIsDown && (( side(abstrial)==1 && KeyCode(leftKey)==1) || (side(abstrial) ==2 && KeyCode(rightKey)==1))
rt(abstrial)= (endtime-starttime); %Compute reaction time
ac=1
end
if KeyIsDown && (( side(abstrial)==1 && KeyCode(rightKey)==1) || (side(abstrial) ==2 && KeyCode(leftKey)==1))
rt(abstrial)= (endtime-starttime); %Compute reaction time
ac=0
textWA = strvcat(['Risposta sbagliata']);
DrawFormattedText(win, textWA, 'center', 'center', [255 255 255]);
Screen('Flip',win);
pause(.3);
end
if KeyIsDown && KeyCode(rightKey)==0 && KeyCode(leftKey)==0 &&KeyCode(escapeKey)==0;
textWB = strvcat(['Ops, tasto sbagliato']);
DrawFormattedText(win, textWB, 'center', 'center', [255 255 255]);
Screen('Flip',win);
pause(.3);
end
if KeyIsDown && KeyCode(escapeKey)
ShowCursor(win);
Screen('CloseAll');
end
break
end
I' ve tried to add waitsecs(2) after the stimulus' flip but it doens't work. I've also tried with
if endtime-startime> 2
end
But this doesn't work too!
How could I add the maximum time of 2 seconds within the while loop?
Thanks!
1 Comment
Jan
on 17 Sep 2017
Note:
textWB = strvcat(['Risposta sbagliata'])
??? What about:
textWB = 'Risposta sbagliata';
Answers (1)
Jan
on 17 Sep 2017
Edited: Jan
on 17 Sep 2017
What is endtime, StimTime, starttime? You have posted a lot of code, which is not related to the actual question, but not the important details.
KeyIsDown = false;
starttime = now; % Perhaps, or a PsychToolbox function?!
while (now - starttime) <= StimTime || KeyIsDown
[KeyIsDown, endtime, KeyCode] = KbCheck;
end
if KeyIsDown
... % Process the pressed key
else
... % Time out while waiting for a key press
end
3 Comments
Jan
on 17 Sep 2017
Sorry, I do not have the PsychToolbox installed and do not know any of the shown commands. Perhaps you want to replace the now in my suggestion be GetSecs.
Walter Roberson
on 17 Sep 2017
KbQueueWait() accepts a maximum wait time as its third parameter. I cannot tell, though, whether it is expecting an absolute time (in what time base?) or a relative time (in seconds?)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!