Wait for a key press or move on with next trial
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Jan
le 17 Sep 2017
Note:
textWB = strvcat(['Risposta sbagliata'])
??? What about:
textWB = 'Risposta sbagliata';
Réponses (1)
Jan
le 17 Sep 2017
Modifié(e) : Jan
le 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 commentaires
Jan
le 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
le 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?)
Voir également
Catégories
En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!