キーボードからの入力(およびキーコード取得)と反応時間計測のサンプル with MATLAB
% 3. Wait for a key with KbWait.
WaitSecs(0.5);
fprintf('?n3 of 4. Testing KbWait: hit any key. Just once.?n');
startSecs = GetSecs;
timeSecs = KbWait;
[keyIsDown,t,keyCode] = KbCheck;
% The initial 1 in the fprintf is needed. Otherwise '5%' won't print.
fprintf(1,'"%s" hit at time %.3f s?n',KbName(keyCode),timeSecs-startSecs);
FlushEvents('keyDown'); % discard all the chars from the Event Manager queue.
% 3. Wait for a key with KbWait.
WaitSecs(0.5);
fprintf('?n3 of 4. Testing KbWait: hit any key. Just once.?n');
startSecs = GetSecs;
timeSecs = KbWait;
[keyIsDown,t,keyCode] = KbCheck;
% The initial 1 in the fprintf is needed. Otherwise '5%' won't print.
fprintf(1,'"%s" hit at time %.3f s?n',KbName(keyCode),timeSecs-startSecs);
FlushEvents('keyDown'); % discard all the chars from the Event Manager queue.