OpenSesame
OpenSesame copied to clipboard
Suggestion: keyboard.flush()-like function returning flushed keys
Occasionally I run into the problem that I need to concurrently wait for key presses and e.g. eye tracker or speech recognition events. I would like to check for pressed keys in a loop similar to how keyboard.get_key()
works, but without the function blocking, or like keyboard.flush()
with more information returned than a simple boolean.
You mean that you would like to have a keyboard.pressed_keys()
function that returns a list of all keys that are currently down? That might be a nice addition, I agree. For now, if you use legacy or xpyriment, you could use get_pressed()
directly from PyGame; I'm not sure if PsychoPy also supports this.
- https://www.pygame.org/docs/ref/key.html#pygame.key.get_pressed
Hm, that might work if the keys are being pressed for long enough, if I understand correctly. I assumed that, for flush to work, somewhere there would have to be a list of keys pressed since the last call to keyboard.pressed_keys()
or since the object has been created...
I see what you mean now. Basically, to disable blocking, you simply specify timeout=0
, and then you should get the behavior you want.