首页 > 解决方案 > 脚本适用于键盘,但仅与响应按钮不一致

问题描述

在我的脚本中,我想在显示不同的刺激 ( , )r时记录响应(键盘或响应按钮单击)。循环(试用)总是显示,然后存储我们需要的响应时间记录的点击时间。可以在试用期间或每次试用中单击一次。image1image2image1image2image1image2

使用键盘按下两个图像期间的记录工作。但是,它只记录在 期间的按钮按下image1,而不是image2。因此,问题不在于没有记录响应,而是按钮实际工作。

我试过:使用不同的响应按钮,使用鼠标作为响应按钮。当我单击响应按钮时,它会r在命令行中写入,也在image1收集期间。

显示时如何使响应按钮起作用image2


startOfTrial = GetSecs;

% Stimulus presentation
    Screen('DrawTexture', myScreen, image1)
    [VBLTimestamp StimulusOnsetTime1] = Screen('Flip', myScreen);

    % Response recording
    [keyIsDown, responseTime1, keyCode] = KbCheck; % saves whether a key has been pressed, seconds and the key which has been pressed.
    while keyCode(BUTTON) == 0 
        [keyIsDown, responseTime1, keyCode] = KbCheck;
        if responseTime1 - StimulusOnsetTime1 >= stimDuration
            Screen('DrawTexture', myScreen, image2);
            [VBLTimestamp StimulusEndTime1]  = Screen('Flip', myScreen);
            if responseTime1 - StimulusOnsetTime1 >= stimDuration + ISI
                break
            end
        end
    end

    if responseTime1 - StimulusOnsetTime1 < stimDuration
        WaitSecs(stimDuration - (responseTime1 - StimulusOnsetTime1));
        [VBLTimestamp StimulusEndTime1]  = Screen('Flip', myScreen); 
    end

    % Checking correctness
    if keyCode(BUTTON) == 1
        RT(trial) = (responseTime1 - StimulusOnsetTime1)*1000; % Converts to milliseconds
        response(trial) = 1;
        if trialList(2, trial) == 1
            correctness(trial) = 1; % Hit
        else
            correctness(trial) = 2; % False Alarm
        end
    else
        response(trial) = 0;
        if trialList(2, trial) == 1
            correctness(trial) = 3; % Miss
        else
            correctness(trial) = 4; % Correct rejection
        end
    end

    c = correctness(trial)

    t2 = GetSecs;
    % Presenting blank screen for remaining time
    if t2 - StimulusEndTime1 < ISI
       Screen('DrawTexture', myScreen, image2);
       Screen('Flip', myScreen);
       WaitSecs(ISI - (t2 - StimulusEndTime1));
    end

标签: matlabpsychtoolbox

解决方案


推荐阅读