Psychtoolbox - exit out of loop with keypress

13 ビュー (過去 30 日間)
Harriet Dempsey-Jones
Harriet Dempsey-Jones 2019 年 6 月 14 日
Hi everyone,
I was wondering if someone could help - I am having a bad computer day. I want to make a really simple program where a
  • random number is presented on screen
  • the program randomly selects whether to +1 or -1 to that number
  • if it chooses to add one, play a high tone - and +1 to the starting number
  • if it chooses to subtract '' low tone '' -1
  • And to keep doing this until a key press happens (enter or escape or something)
I have put something together that basically works, aside from the exiting out on keypress - the program does not seem to get/ respond to key presses inside the program i.e., my KbCheck at line 98 does not seem to work. As I press it just types into the main screen.
keyIsDown = 0; % initialise to 0
while 1 % keep running until Q is pressed
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if (keyIsDown)
if keyCode(escKey)
ShowCursor;
Screen('CloseAll');
return
else
end
end
The thing I used to wait until mouse is clicked between trials works but looks a bit messy
clear buttons
[~,~,buttons]=GetMouse;
while ~any(buttons)
[~,~,buttons]=GetMouse;
end
clear buttons
[~,~,buttons]=GetMouse;
Any help would be greatly appreciated!

回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by