Hi,
I’m having a problem with KbStrokeWait as well as [keyIsDown,TimeStamp,keyCode] = KbCheck; functions when I use a MRI-compatible button box that mimics keyboard presses (keys 3,4,5) on a Windows lap top.
During my PTB task, key presses on this button box does registers only some times with a delay (mostly doesn’t at all) despite the fact that the button box responses show up immediately on any other software almost immediately including Matlab command window.
Below are two examples. First one is a simple KbStrokeWait function to move from one screen to another during instructions…
Screen(‘Flip’,display.windowPtr); WaitSecs(UntilKey);
KbStrokeWait;
as well as when I assign values to the button box presses in a while loop…
while 1
[keyIsDown,TimeStamp,keyCode] = KbCheck;
if GetSecs - RespStart >= TrialDeadline %If the duration of the respond exceeded the deadline, then break the while loop
Exceed = 1; %then exceed is 1, which makes the response incorrect and then gives the feedback ‘Respond faster’
break
end
if keyIsDown
if (~keyCode(endcode))
if (keyCode(rightkey)); Resp=1; end
if (keyCode(leftkey)); Resp=0; end
if (~keyCode(rightkey) && ~keyCode(leftkey));Resp=9;end
break;
else
Screen(‘TextSize’, display.windowPtr, 25);
DrawFormattedText(display.windowPtr, sprintf(’%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s’, …
‘Press ESC to quit the game or press any key to continue.’), ‘center’, ‘center’,[255 255 255], [100],[],[],[1.25]);
Screen(‘Flip’,display.windowPtr);
WaitSecs(UntilKey)
while KbCheck;
end;
while 1
[keyIsDown,TimeStamp,keyCode] = KbCheck;
if keyIsDown
if (keyCode(endcode))
Screen(‘TextSize’, display.windowPtr, 25);
DrawFormattedText(display.windowPtr, 'Study is over. Thanks for your participation! ', ‘center’, ‘center’, [255 255 255], [100]);
Screen(‘Flip’,display.windowPtr);
WaitSecs(2);
Screen(‘CloseAll’);
ListenChar(0);
ShowCursor;
elseif (~keyCode(endcode))
break;
end
end
end
end
while KbCheck;end; % wait until key is released.
end
end