2016-12-24 297 views
0
while 1 

    ch = GetChar 
    KbWait 
    if (ch>48) && (ch<53) 
     trial(j).RT = GetSecs - startTime ; 
     break; 
    end 
    end 

這裏是我的示例代碼,我正在Stroop Task上工作,我期待着加速反應時間。反應時間從刺激呈現開始並以按鍵結束。我使用上面的代碼來壓縮整個鍵盤,期望1-2-3-4的數字。然而,有時候所有的按鍵都可以被按下,而不僅僅是1-2-3-4。我曾經嘗試過很多次,有時候它會壓制鍵,有時卻不會。我真的不明白原因。在MATLAB的PTB中使用getchar

回答

1

GetChar()函數等待按鍵,或從隊列中檢索以前按下的鍵:http://docs.psychtoolbox.org/GetChar。可能發生的情況是,您在GetChar正在讀取的隊列中存在以前的按鍵,即使它們不是最新的按鍵。

但是,Psychtoolbox開發人員建議不要使用GetChar()函數來收集響應時間。這是由於GetChar()與其他函數(如KbCheck())的時序預測有關。

下面的代碼片段可用於輪詢鍵盤的響應時間:

% find the keyscan codes for the first four number keys 
% (top of the keyboard keys, number pad keys have different codes) 
keysToWaitFor = [KbName('!1'), KbName('[email protected]'), KbName('3#'), KbName('4$')]; 

responded = 0; 
while responded == 0 

    [tmp,KeyTime,KeyCode] = KbCheck(-3); 

    if KeyCode(keysToWaitFor) 
     trial(j).RT = KeyTime - startTime; 
     responded = 1; 
    end 

    % time between iterations of KbCheck loop 
    WaitSecs(0.001); 
end