What command to accept/reject trial with left button press for eye tracker

2 次查看(过去 30 天)
Hello,
We are doing a project involving eye tracking and EEG measurements, with a PING being sent to the EEG when we accept/reject a trial. Most of the code is specified for a space bar and not a button press, but we need to indicate if we accepted or rejected a trial on the eye tracker which requires a left button press. What command can we use for this?
See below for an example of the code. We believe the command we need would be added before the fprintf(s2,'12') line:
if target_type==1;
fprintf(s2, '00'); %reset USB BBT module code line
Anti_only;
fprintf(s2, '0B'); %BBT ping for fixation cross baseline
disp('EEG baseline recording press enter to continue')
pause;
anti_Fix_left_far;
fprintf(s2, '03'); %ping code for anti_left_far
WaitSecs(rand()*(max_wait_time - min_wait_time) + min_wait_time); %%%%this needs to be randomized between 900 and 1,000 ms for fixation extinguish
Anti_only;
fprintf(s2, '01'); %%%%ping for target extinction
WaitSecs(0.9)
if strcmp(button, 'Yes')
fprintf(s2,'12'); %%% PING EEG computer to denote a "GOOD trial". %%%ADDED BY Michelle ON DEC 3, 2021
elseif strcmp(button, 'No')
fprintf(s2,'13'); %%% PING EEG computer to denote a "BAD TRIAL". %%%ADDED BY Michelle ON DEC 3, 2021
gap=2;
task=2;
eccentricity=2;
space=2;
fprintf(s2, '00');%%%%ping for clearing BBT module
disp('GUI should go up')
end
end

采纳的回答

Alagu Sankar Esakkiappan
I see that you are trying to detect a keystroke from keyboard to perform further actions in your MATLAB code. This may easily be achieved using waitforbuttonpress to wait for a keystroke and then obtaining keystroke input from current figure using get function.
You may refer to the following code snippet for reference:
k = waitforbuttonpress; % Waits in this line till a Keystroke is detected
value = double(get(gcf,'CurrentCharacter')); % Stores the ASCII value for detected Keystroke
close(gcf); % Closes the Figure opened for detecting Keystroke
target = 28; % ASCII value for "Left Button" press
if ( value == target ) % Check if "Left Button" is pressed
disp('Left Button pressed');
else
disp('Left Button not pressed');
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by