Wait for a key press or move on with next trial

3 ビュー (過去 30 日間)
Laura Pizzato
Laura Pizzato 2017 年 9 月 17 日
コメント済み: Walter Roberson 2017 年 9 月 17 日
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 件のコメント
Jan
Jan 2017 年 9 月 17 日
Note:
textWB = strvcat(['Risposta sbagliata'])
??? What about:
textWB = 'Risposta sbagliata';

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2017 年 9 月 17 日
編集済み: Jan 2017 年 9 月 17 日
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 件のコメント
Jan
Jan 2017 年 9 月 17 日
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
Walter Roberson 2017 年 9 月 17 日
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?)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by