【问题标题】:Waiting for specific time for clicking right or left button on mouse, then continue等待特定时间单击鼠标右键或左键,然后继续
【发布时间】:2021-10-13 13:42:31
【问题描述】:

我对以下问题有疑问: 我在左耳或右耳随机产生了一些声音,参与者应按下鼠标上的左键或右键(这意味着如果左耳出现声音,则应按下左键)。 我的问题是这样的:参与者只有 3 秒钟的点击时间,然后脚本应该继续。 (我有两种方法:一种方法如果我在 psychtoolbox 中使用 GetClicks 它将暂停(不应该暂停),第二种方法如果我在 psychtoolbox 中使用 GetMouse 我无法定义 左右按钮)。 如果有人有任何想法,请告诉我我真的需要它。提前致谢。

%% 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

【问题讨论】:

    标签: psychtoolbox


    【解决方案1】:

    可以确定是使用GetMouse 按下了左键还是右键。从GetMouse 返回的按钮数组是一个逻辑数组,鼠标上的每个按钮都有 1 个元素。例如:

    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
    

    【讨论】:

    • 你是对的。非常感谢。我非常感谢您的帮助。在我的脚本的一小部分我犯了一个错误,现在通过你的评论我意识到我的错误。再次非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2010-10-18
    相关资源
    最近更新 更多