If I use GetMouse in a loop, as you can see below… the program is hanging up after one round…
try
% Open up a window on the screen and clear it.
whichScreen = max(Screen('Screens'));
[theWindow,theRect] = Screen(whichScreen,'OpenWindow',0);
Priority(MaxPriority(0));
ListenChar(2);
n_zaehler=3;
for zaehler=1:n_zaehler;
Screen('TextFont',theWindow, 'Arial');
Screen('TextSize',theWindow, 24);
Screen('TextStyle', theWindow, 255);
DrawFormattedText(theWindow, 'Hit any key to go on', 'center', 708, 255);
Screen('Flip', theWindow);
KbWait;
WaitSecs(1.0);
Screen('Flip', theWindow);
% Move the cursor to the center of the screen
x = theRect(RectRight)/2;
y = theRect(RectBottom)/2;
SetMouse(x,y);
[x,y,buttons] = GetMouse(theWindow);
while any(buttons) % if already down, wait for release
[x,y,buttons] = GetMouse(theWindow);
thePoints = [x, y];
end
while ~any(buttons) % wait for press
[x,y,buttons] = GetMouse(theWindow);
thePoints = [x, y];
end
while any(buttons) % wait for release
[x,y,buttons] = GetMouse(theWindow);
thePoints = [x, y];
end
if x<=theRect(RectRight)/2
fprintf ('the key is c');
else
fprintf ('the key is m');
end
%Screen('Flip', theWindow);
ShowCursor;
WaitSecs(1.0);
end
% Close up
ShowCursor;
ListenChar(0);
Screen(theWindow,'Close');
catch
Screen('CloseAll')
ShowCursor;
psychrethrow(psychlasterror);
ListenChar(0);
end %try..catch..
I want to trace a movement with the mouse as a response in an experiment…
Got some idea?
Steffi