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