In my task (pseudo code below), I use a while loop (that runs for ~90sec until a block is done) in which the screen is continuously redrawn to show smooth motion.
I want to detect in that loop whether participants press buttons (and which ones) - they might be pressing a sequence of several buttons. I’m using kbcheck for this. This works. The problem is that sometimes button presses get detected more than once (e.g. I pressed ‘k’ once, but in my log file it’s listed 2x).
How can I solve this? Here are some options I’ve thought about, but I’m not sure which one would be best:
- put in a forced pause (e.g. 20 msec) after a button press is detected. This works - Is there any that could go wrong with this?
- store the time of the button press and record future presses only if it’s e.g. more than 20msec after the previous button press
- should I use the “Flip” command with a specified time rather than run the while loop as quickly as possible?
- Is there a better command than the KbCheck → if keycode(…) combination of commands that I can use? E.g. is there somehow a way to delete keyCode automatically after I’ve compared it? I guess I could myself set it to empty after a button press has been detected?
while GetSecs < finishTime % Draw screen to produce smooth motion draw_my_screen() % lots of commands to compute what should be on the screen at each time point t Flip('Screen',my_window) % Check for button press [keyIsDown,block_vars.currentTime ,keyCode] = KbCheck; % check button presses if keyCode(my_key_of_interest) % Save the key press to my data matrix save_key(my_key_of_interest) end end
macOS Catalina (10.15.7)
Pyschtoolbox version: 3.0.17