Hi there,
I am working on a script in which I would like to be able to detect when the mouse stops moving, for say, 1.5 seconds. I am making this program for an fMRI study. So that the sample script makes a bit more sense, I want the program to start when the "5" key is pressed, after which point the participant has 8 seconds to decide how much money to send to another player. The participant will be moving the mouse up and/or down, to pick a number between 1-10. There is a display that shows how much money is being kept/sent, which is taken care of by a separate function 'meter'. here is a sample script that I am working with. The last few lines are where I am trying to set up some sort of timer, or something that will detect when the mouse stops moving, but only if it hasn't moved for multiple seconds. The problem is that my program is based around a constantly refreshing screen, so I'm not sure how I can time how long it has been since the mouse has moved.
-----
clear all; close all; clc;
KbName('UnifyKeyNames');
[wPtr,rect]=Screen('OpenWindow',screenNum);
white=WhiteIndex(wPtr);
black=BlackIndex(wPtr);
Screen('FillRect',wPtr,black);
fiveKey = KbName('5%');
escapeKey = KbName('ESCAPE');
[x,y,buttons] = GetMouse;
while 1
[ keyIsDown, secs, keyCode ] = KbCheck;
if keyIsDown
if keyCode(escapeKey)
break;
end
end
if keyIsDown
if keyCode(fiveKey)
num_iter = 11;
frameSize = [rect(3)/2-50 rect(4)/2-150 rect(3)/2+50 rect(4)/2+150];
iteration = linspace(frameSize(4),frameSize(2),num_iter);
X = frameSize(3); Y = frameSize(4);
R = 0;
SetMouse(X, Y, R);
% display meter %%%%%%%%%%%%%%%%%%%%%
DrawFormattedText(wPtr,['SEND $0' ('\n\n') 'KEEP $10'],...
((frameSize(2)+frameSize(4))/2)-75,'center');
Screen('Flip',wPtr);
startSecs = GetSecs;
tic
while toc < 8
[NewX,NewY] = GetMouse;
response = meter(num_iter, iteration, frameSize, NewY, wPtr);
DrawFormattedText(wPtr,['SEND $' num2str(response) ('\n\n') 'KEEP $' num2str((num_iter-1)-response)],...
((frameSize(2)+frameSize(4))/2)-75,'center', white);
Screen('Flip',wPtr);
[NewX2,NewY2] = Getmouse;
if NewX2 == NewX && NewY2 == NewY
startCount = GetSecs;
DrawFormattedText(wPtr,'Hello', 'center', 'center');
end
end
endSecs = GetSecs;
SmallBlank(wPtr, params);
%%%time between screen Flip and end of WaitSecs
time_diff = endSecs - startSecs;
%%%
break;
end
end
end
Screen('CloseAll');
-----
I hope this isn't too confusing, based on my explanation. I will be happy to explain in more detail. General help is much appreciated as well.
Patrick
I am working on a script in which I would like to be able to detect when the mouse stops moving, for say, 1.5 seconds. I am making this program for an fMRI study. So that the sample script makes a bit more sense, I want the program to start when the "5" key is pressed, after which point the participant has 8 seconds to decide how much money to send to another player. The participant will be moving the mouse up and/or down, to pick a number between 1-10. There is a display that shows how much money is being kept/sent, which is taken care of by a separate function 'meter'. here is a sample script that I am working with. The last few lines are where I am trying to set up some sort of timer, or something that will detect when the mouse stops moving, but only if it hasn't moved for multiple seconds. The problem is that my program is based around a constantly refreshing screen, so I'm not sure how I can time how long it has been since the mouse has moved.
-----
clear all; close all; clc;
KbName('UnifyKeyNames');
[wPtr,rect]=Screen('OpenWindow',screenNum);
white=WhiteIndex(wPtr);
black=BlackIndex(wPtr);
Screen('FillRect',wPtr,black);
fiveKey = KbName('5%');
escapeKey = KbName('ESCAPE');
[x,y,buttons] = GetMouse;
while 1
[ keyIsDown, secs, keyCode ] = KbCheck;
if keyIsDown
if keyCode(escapeKey)
break;
end
end
if keyIsDown
if keyCode(fiveKey)
num_iter = 11;
frameSize = [rect(3)/2-50 rect(4)/2-150 rect(3)/2+50 rect(4)/2+150];
iteration = linspace(frameSize(4),frameSize(2),num_iter);
X = frameSize(3); Y = frameSize(4);
R = 0;
SetMouse(X, Y, R);
% display meter %%%%%%%%%%%%%%%%%%%%%
DrawFormattedText(wPtr,['SEND $0' ('\n\n') 'KEEP $10'],...
((frameSize(2)+frameSize(4))/2)-75,'center');
Screen('Flip',wPtr);
startSecs = GetSecs;
tic
while toc < 8
[NewX,NewY] = GetMouse;
response = meter(num_iter, iteration, frameSize, NewY, wPtr);
DrawFormattedText(wPtr,['SEND $' num2str(response) ('\n\n') 'KEEP $' num2str((num_iter-1)-response)],...
((frameSize(2)+frameSize(4))/2)-75,'center', white);
Screen('Flip',wPtr);
[NewX2,NewY2] = Getmouse;
if NewX2 == NewX && NewY2 == NewY
startCount = GetSecs;
DrawFormattedText(wPtr,'Hello', 'center', 'center');
end
end
endSecs = GetSecs;
SmallBlank(wPtr, params);
%%%time between screen Flip and end of WaitSecs
time_diff = endSecs - startSecs;
%%%
break;
end
end
end
Screen('CloseAll');
-----
I hope this isn't too confusing, based on my explanation. I will be happy to explain in more detail. General help is much appreciated as well.
Patrick