0

I have a problem with this following issue: I generated some sounds in left or right ear randomly and participants should push the left or right button on mouse (it means if a sound has been presented in the left ear, left button should been pushed ). My problem is this: participants have just3 seconds for clicking and after that the script should continue. (I have 2 ways: one way if I use GetClicks in psychtoolbox it will pause (it should not be paused) and second way if I use GetMouse in psychtoolbox I can not define right or left button). Please if anyone have any ideas tell me about that I really need it. Thanks in advance.

%% 1) First way: using from GetClicks causes pause 
clc
clear;
SamplingRate=48000;
F=[250 500 1000 2000 4000];
t=linspace(0,1,SamplingRate);
ind=0;
memory{1,1}={0};
for i=1:length(F)
ind=1+ind;
Frequency = F(i);
y=sin(t*2*pi*Frequency);
sound(y,SamplingRate) ;
%% This here I want to wait 3 second for clicking, after that the script continues but it will stope by using GetClicks
[clicks,~,~,whichButton] = GetClicks; %% This function is related to the Psychtoolbox in Matlab
%%
pause(5)
memory{1,ind} = y';
end
 

%% 2. Second way: using GetMouse is good but I can not define right or left button in this code
clc
clear;
SamplingRate=48000;
wait4resTime = 3;
F=[250 500 1000 2000 4000];
t=linspace(0,1,SamplingRate);
ind=0;
memory{1,1}={0};
Z=[];
for i=1:length(F)
ind=1+ind;
Frequency = F(i);
y=sin(t*2*pi*Frequency);
    tStart=GetSecs;
sound(y,SamplingRate) ;
%% This here I want to wait 3 second for clicking, after that the script continues but I can not define the right or left button 
    MousePress=0; %initializes flag to indicate no response
    while    (MousePress==0 && ( (GetSecs-tStart) < wait4resTime-.1 )) 
        [x,y,buttons]=GetMouse();  %waits for a key-press
     MousePress=any(buttons);  %% I have problem and I can not define right or left button this here.
        Z(1,jnd)=MousePress;      
    end
        elapsedTime = GetSecs-tStart;
%%
pause(4)
memory{1,ind} = y';
end

1 Answers1

0

You can determine if the left or right button was pressed with GetMouse. The buttons array that is returned from GetMouse is a logical array with 1 element for each button on the mouse. For example:

MousePress = 0;
while(~MousePress)
    [x, y, buttons] = GetMouse();
    MousePress = any(buttons);
end

disp(buttons)

if(buttons(1))
    disp('pressed left button!')
end

if(buttons(2))
    disp('pressed right button')
end
DMR
  • 1,479
  • 1
  • 8
  • 11
  • You are right. Thanks a zillion. I really appreciate for this helping. In a small part of my script I made a mistake and now by your comment I realized my mistake. Thanks a lot again. – mohadeseh Oct 15 '21 at 19:44