【问题标题】:How to display stimuli depending on keyboard response如何根据键盘响应显示刺激
【发布时间】:2020-08-25 17:58:27
【问题描述】:

我在 Windows 10 系统上的 Psychtoolbox 上使用 MATLAB R2020a。我正在尝试根据用户提供的键盘响应在屏幕上呈现刺激。我正在使用 if-else 语句对此进行编码,但只显示固定十字,并且没有显示错误消息。当出现问号时,用户按下箭头键,并在此基础上呈现下一个刺激。

我也不确定如何区分启动任务时给出的 Kb 响应和问号后给出的响应。有人可以帮我解决这个问题吗?

% Question mark
Screen('FillRect', window, white);
Screen('DrawTextures', window, imageTexture, [], dstRects);
Screen('Flip', window)
KbStrokeWait;

% Experimental instructions
Screen('FillRect', window, grey);
Screen('DrawText', window, line3, screenXpixels*0.2, screenYpixels*0.4, white);
Screen('DrawText', window, line4, screenXpixels*0.2, screenYpixels*0.5, white);
Screen('Flip', window);
KbStrokeWait;

% Fixation cross
Screen('DrawLines', window, allCoords,lineWidthPix, white, [xCenter yCenter], 2);
Screen('Flip', window, [], 1);
WaitSecs(1);

% Draw rect frames

% Check the keyboard to see if a button has been pressed
    [keyIsDown,secs, keyCode] = KbCheck;
    
% Present stimulus   
if KbCheck == leftKey
    Screen('DrawText', window, num2str(seq1), rightX, rightY, [0 1 0]);
    Screen('DrawText', window, num2str(seq3), leftX, leftY, [1 0 1]);
    Screen('Flip', window);
    WaitSecs(0.5);
elseif KbCheck == rightKey
    Screen('DrawText', window, num2str(seq2), leftX, leftY, [1 1 0]);
    Screen('DrawText', window, num2str(seq3), rightX, rightY, [1 0 1]);
    Screen('Flip', window);
    WaitSecs(0.5);
elseif KbCheck == upKey
    Screen('DrawText', window, num2str(seq1), rightX, rightY, [0 1 0]);
    Screen('DrawText', window, num2str(seq2), leftX, leftY, [1 1 0]);
    Screen('Flip', window);
    WaitSecs(0.5);
end

【问题讨论】:

    标签: matlab keyboard screen psychtoolbox


    【解决方案1】:

    在您的示例中,您正在调用 KbCheck 函数并将结果与​​ leftKeyrightKey 等进行比较。但是 KbCheck 的第一个输出只是一个布尔值,指示是否有任何键被按下。而是使用 KbCheck 函数中的 keyCode 矩阵,并比较每个键是否被按下。

    在您的示例中,您也不是连续轮询键盘,而是显示固定 1 秒,然后在该秒过去后检查一次键盘。下面是一个更正键比较的示例,以及在注视开始后 1 秒检查键盘。在这里,我已将绘制到屏幕的调用替换为简单地将消息打印到 MATLAB 控制台,以简化示例。

    leftKey = KbName('LeftArrow');
    rightKey = KbName('RightArrow');
    upKey = KbName('UpArrow');
    
    % don't display write keyboard responses into the MATLAB window
    ListenChar(2);
    
    % how long to poll for a response following fixation onset
    responseSeconds = 1;
    
    % Question mark
    disp('?');
    KbStrokeWait(-3);
    
    % Experimental instructions
    disp('Instructions Here');
    KbStrokeWait(-3);
    
    % Fixation cross
    
    disp('+');
    fixationOnset = GetSecs();
    keyPressed = 0; % store whether a response has been made
    
    while (GetSecs - fixationOnset) <= responseSeconds
        
        % Check the keyboard to see if a button has been pressed
        [keyIsDown,secs, keyCode] = KbCheck(-3);
        
        if keyPressed == 0 && keyIsDown
            if keyCode(leftKey)
                disp('pressed the left key');
            elseif keyCode(rightKey)
                disp('pressed the right key');
            elseif keyCode(upKey)
                disp('pressed the up key');
            end
            keyPressed = 1; % indicate the response has been made
        end
        
        % Wait 1 ms before checking  again to prevent
        % overload of the machine at elevated priority
        WaitSecs(0.001);
    end
    
    disp('response loop over');
    
    WaitSecs(0.5);
    
    disp('wait time over');
    
    ListenChar();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2012-04-20
      • 1970-01-01
      • 1970-01-01
      • 2012-07-03
      • 1970-01-01
      相关资源
      最近更新 更多