Here is a simple script to run KbQueue, enlighted by ajb12490's previous post. It seems working. Please let me know if anyone thinks it is still buggy or wrong. Thanks!
%--------- the script ------------------
commandwindow
KbName('UnifyKeyNames');
try
w = Screen('OpenWindow', 0, 0, [0 0 640 480]);
Screen('FillRect',w,127);
Screen('Flip',w);
escapeKey = KbName('ESCAPE');
spaceKey = KbName('space');
startSecs = GetSecs;
KbQueueCreate;
KbQueueStart;
while 1
Screen('FillRect',w,127);
Screen('Flip',w);
[keyIsDown, firstKeyPressTimes, firstKeyReleaseTimes, lastKeyPressTimes, lastKeyReleaseTimes]=KbQueueCheck;
t1 = firstKeyPressTimes(find(firstKeyPressTimes));
t2 = lastKeyPressTimes(find(lastKeyPressTimes));
t3 = firstKeyReleaseTimes(find(firstKeyReleaseTimes));
t4 = lastKeyReleaseTimes(find(lastKeyReleaseTimes));
if keyIsDown
fprintf('"%s" typed at time %.3f seconds\n', KbName(firstKeyPressTimes), t1 - startSecs);
fprintf('"%s" typed at time %.3f seconds\n', KbName(lastKeyPressTimes), t2 - startSecs);
disp('');
if firstKeyPressTimes(escapeKey)
break;
end
end
if length(unique(firstKeyReleaseTimes)) > 1 || length(unique(firstKeyReleaseTimes)) > 1
fprintf('"%s" released at time %.3f seconds\n', KbName(firstKeyReleaseTimes), t3 - startSecs);
fprintf('"%s" released at time %.3f seconds\n', KbName(lastKeyReleaseTimes), t4 - startSecs);
disp('');
end
end
PsychHID('KbQueueRelease')
sca;
catch ME
sca;
psychlasterror.message = ME.message;
psychrethrow(psychlasterror);
end
%------------------------ the output here -----------------
"LeftArrow" typed at time 0.558 seconds
"LeftArrow" typed at time 0.558 seconds
"RightArrow" typed at time 1.677 seconds
"RightArrow" typed at time 1.677 seconds
"LeftArrow" released at time 1.712 seconds
"LeftArrow" released at time 1.712 seconds
"LeftArrow" typed at time 2.897 seconds
"LeftArrow" typed at time 2.897 seconds
"RightArrow" released at time 2.936 seconds
"RightArrow" released at time 2.936 seconds
"RightArrow" typed at time 4.086 seconds
"RightArrow" typed at time 4.086 seconds
"LeftArrow" released at time 4.123 seconds
"LeftArrow" released at time 4.123 seconds
"RightArrow" released at time 5.381 seconds
"RightArrow" released at time 5.381 seconds
"DownArrow" typed at time 5.391 seconds
"DownArrow" typed at time 5.391 seconds
"RightArrow" typed at time 6.565 seconds
"RightArrow" typed at time 6.565 seconds
"DownArrow" released at time 6.609 seconds
"DownArrow" released at time 6.609 seconds
"RightArrow" released at time 7.795 seconds
"RightArrow" released at time 7.795 seconds
"LeftArrow" typed at time 7.804 seconds
"LeftArrow" typed at time 7.804 seconds
"LeftArrow" released at time 8.800 seconds
"LeftArrow" released at time 8.800 seconds
"UpArrow" typed at time 8.811 seconds
"UpArrow" typed at time 8.811 seconds
"UpArrow" released at time 9.821 seconds
"UpArrow" released at time 9.821 seconds
"RightArrow" typed at time 9.956 seconds
"RightArrow" typed at time 9.956 seconds
"LeftArrow" typed at time 10.973 seconds
"LeftArrow" typed at time 10.973 seconds
"RightArrow" released at time 10.962 seconds
"RightArrow" released at time 10.962 seconds
"LeftArrow" released at time 11.726 seconds
"LeftArrow" released at time 11.726 seconds
"ESCAPE" typed at time 11.767 seconds
"ESCAPE" typed at time 11.767 seconds