1

In my script I want to record responses (keyboard r or response button click) while I show different stimuli (image1, image2). The loop (trial) always shows image1, then image2 and stores the recorded time of the click as we need the response times. One can click during image1 or image2 but only once per trial.

Recording works during both images with keyboard presses. However, it only records button presses during image1, not image2. Therefore, the problem is not that responses are not recorded, the buttons work actually.

I tried: Using different Response Buttons, using mouse as response button. When I click the response button, it writes r in the commandline, also during image1 it is collected.

How can I get the response button to work when showing 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
yenea
  • 11
  • 3
  • What is the 'image2', the cross texture you draw via Screen('DrawTexture', myScreen, cross);? – DMR Sep 12 '19 at 01:18
  • I did change the variable names to image1 and image2 to match it to the question. I hope this clarifies it. Thank you. – yenea Sep 12 '19 at 07:53
  • It looks like you're only polling for a single button, the value of BUTTON. How are you determining that you're only registering a press during image1 and not image2, via the logged response time? – DMR Sep 13 '19 at 01:42
  • I record the time the button is pressed, therefore I can tell that only presses during image1 (500 msec) are recorded. I also tested this by pressing only during image1 or image2 and then checking the log file. – yenea Sep 13 '19 at 07:00
  • While you didn't provide all values needed to reproduce this example (stimDuration, ISI, etc.) the existing code seems to be working as you described, a keyboard button press is captured during either the first or second stimulus with the appropriate response time. Is the keyboard button you're having issue with, or a mouse click? – DMR Sep 14 '19 at 18:48

0 Answers0