Buttonbox delay

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

This sounds very similar to my issue and I’m curious if you found a solution.

MRI-compatible button box key presses register to Matlab command window, PsychoPy, and everywhere else, but only intermittently to PTB. Same behavior on Windows PC, Windows laptop, and MacBook Pro.

Minimal code to reproduce the issues is just two lines:

WaitSecs(0.1); % time for release of any keys
KbWait(-1) % wait for input from any keyboard

Running this and pressing the button box registers about 1 in 10 button pushes despite the same button pushes registering on the command line.

Your interface is from CurDes, right? I believe this has been a known issue for a long time. The cause is their smart design of fake button release. If you configure your interface to not use this feature, you can avoid this problem, while you may suffer the problem of repeated button press if the button is held down longer than usual.

My suggestion is to use KbQueue series function, and avoid to use any function that calls KbCheck. At our MRI center, I had to use the TTL output from the interface, and convert it into a home-made USB keypad. This solves the KbCheck issue, but it is far from a perfect solution, since my device can deal with only 4 buttons plus the trigger. When people use more than 4 buttons or joystick etc., we have to switch back to the CurDes USB output (of course we cannot use KbCheck then).

PTB has a serial port solution for this. But I would say the KbQueue is much superior to serial solution.

I also suggested CueDes to make the fake button release later after the press (40 ms for example), but they did not take it.

2 Likes

Yes, KbQueue functions and also KbEventGet etc. are the way to go for robust input, etc., cfe. KbQueueDemo. KbCheck, KbWait etc. all only poll the exact state at time of query, so deficiently designed “keyboard like” hardware like yours will fool them.

My experience with Cedrus products ten years ago was deficient hardware and firmware design, buggy, bad customer support. Apparently that has not improved much.

Edit: I meant Cedrus response boxes wrt. low quality, not Curdes products. Similar name, but different companies.

-mario