Function event.getKeys() executes regardless of the condition

URL of experiment: /

Description of the problem: event.getKeys() function executes without keys actually being pressed. You can see in the photos that this function literally executes a few hundred times although the designated key was never pressed at that instance (it gets pressed in the previous routine). I tried clearing up the buffer with event.clearEvents(), but this didn’t work out. Does anyone know how to fix this? This is important since this serves me as a condition for text stimuli (a key gets pressed and the stimuli disappears from the screen - it now disappears right at the beginning of the routine regardless of what happens with the keyboard). Thanks!

You seem to have event.getKeys() in code but also a keyboard component.

if event.getKeys(“space”) is always true.

You want (in Python)

if event.getKeys() == 'space':

Thank you for your effort, wakecarter!
Yes, you were right, I somehow put the stop condition in the keyboard component instead of the text component. But now that I fixed this, the opposite happens - when I press the button, nothing occurs and the word stays on the screen until the routine is finished. You can see screenshots of the console, the text component, and the code component and maybe you will be able to figure out why the press of the button doesn’t get logged like it should (I get console log for ‘checkpoint1’ but not for ‘key pressed’).

Screenshot 2020-11-27 at 10.05.12

I normally use keys = event.getKeys()
and then
if ‘space’ in keys:

So perhaps you need if ‘space’ in event.getKeys() or if event.getKeys()==[‘space’] since event.getKeys might always return an array.

1 Like

Thanks wakecarter! The first one turned out to work for me:
if ‘space’ in event.getKeys():

1 Like