Wait for a key press or move on with next trial
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 17 Sep. 2017
Note:
textWB = strvcat(['Risposta sbagliata'])
??? What about:
textWB = 'Risposta sbagliata';
Antworten (1)
Jan
am 17 Sep. 2017
Bearbeitet: Jan
am 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 Kommentare
Jan
am 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
am 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?)
Siehe auch
Kategorien
Mehr zu Timing and presenting 2D and 3D stimuli finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!