# Waiting for specific time for clicking right or left button on mouse, then continue

**URL:** <https://psychtoolbox.discourse.group/t/waiting-for-specific-time-for-clicking-right-or-left-button-on-mouse-then-continue/4067>\
**Category:** Programming Help\
**Created:** [October 13, 2021, 12:57pm UTC](https://psychtoolbox.discourse.group/t/waiting-for-specific-time-for-clicking-right-or-left-button-on-mouse-then-continue/4067 "2021-10-13T12:57:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohadeseh](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/mohadeseh/32/280_2.png) [@Mohadeseh](https://psychtoolbox.discourse.group/u/Mohadeseh)\
**Post date:** [October 13, 2021, 12:57pm UTC](https://psychtoolbox.discourse.group/t/waiting-for-specific-time-for-clicking-right-or-left-button-on-mouse-then-continue/4067/1 "2021-10-13T12:57:32Z")

</div>

Hello everybody, 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

```matlab
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

```

1. Second way: using GetMouse is good but I can not define right or left button in this code

```matlab
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

```

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [October 13, 2021, 2:35pm UTC](https://psychtoolbox.discourse.group/t/waiting-for-specific-time-for-clicking-right-or-left-button-on-mouse-then-continue/4067/2 "2021-10-13T14:35:07Z")

</div>

Type in `doc GetMouse` to get the help for this function, specifically `buttons` will tell you which button was pressed.

[http://psychtoolbox.org/docs/GetMouse](http://psychtoolbox.org/docs/GetMouse)

> “buttons” is a 1xN matrix where N is the number of mouse buttons. Each element of the matrix represents one mouse button. The element is true (1) if the corresponding mouse button is pressed and false (0) otherwise

Instead of using `any(buttons)` you need to see which button is pressed. IIRC the order of `buttons` is platform specific.

---

<div class="post-metadata">

**Author:** ![Mohadeseh](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/mohadeseh/32/280_2.png) [@Mohadeseh](https://psychtoolbox.discourse.group/u/Mohadeseh)\
**Post date:** [October 13, 2021, 8:21pm UTC](https://psychtoolbox.discourse.group/t/waiting-for-specific-time-for-clicking-right-or-left-button-on-mouse-then-continue/4067/3 "2021-10-13T20:21:44Z")

</div>

How should I use button in this code?? Can you explain more about using **button** for finding **which button** has been pushed? I really need it and I do not know, which one that I should use, _ **GetMouse** _ or _ **GetClicks** _ in psychtoolbox???  
I really stuck in this part.

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [October 14, 2021, 3:31am UTC](https://psychtoolbox.discourse.group/t/waiting-for-specific-time-for-clicking-right-or-left-button-on-mouse-then-continue/4067/4 "2021-10-14T03:31:57Z")

</div>

`whichButton = find(buttons);`
