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 CenterFile Exchange에서 Timing 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