Hey everyone,
I want to monitor when space bar is pressed and released again. I would like to monitor press and release as separate events. However, I encountered an unexpected behavior which can be reproduced with this example
from psychopy.hardware import keyboard
kb = keyboard.Keyboard()
for i in range(5):
kb.clearEvents()
key = kb.waitKeys(keyList=["space"], waitRelease=False) # wait for press
print("press!")
key = kb.waitKeys( # wait for release
maxWait=1,
keyList=["space"],
waitRelease=True,
clear=False,
)
print("release!")
print(key)
del key
On the first iteration of the loop, it is working as expected: After pressing space I see the printout "press!" and if I keep holding it down until maxWait has passed I see "release!" and the value of the key variable will be None. However, on the second iteration, it immediately jumps from "press!" to "release!" and key contains a key press. Why does this happen? Shouldn’t calling clearEvents() clear all key presses? I played around with the clear argument of the waitKeys() method, but it had no effect on this behavior. Not sure if this is a bug, or I don’t understand how the kbQueue works …