psychopy.org | Reference | Downloads | Github

Multiple "event.getKeys" in Code components

Hello everyone,

I’m having trouble importing an experiment to Pavlovia. In a routine i have a code component that is something like this in Python and works just fine:

key_1 = event.getKeys(‘space’)
key_2 = event.getKeys(‘t’)

if ‘space’ in key_1:
-> do a lot of stuff

if ‘t’ in key_2:
-> do a lot of stuff

I have translated the code in JS but when piloting the experiment online only the first “event.getKeys” works, so for exemple if the code is writtn like this:

key_1 = event.getKeys(‘space’)
key_2 = event.getKeys(‘t’)

Pressing ‘space’ works as intended but pressing ‘t’ does nothing. On the other hand if the code is written like this:

key_2 = event.getKeys(‘t’)
key_1 = event.getKeys(‘space’)

Pressing ‘t’ works as intended but pressing ‘space’ does nothing.

Does anyone know how to fix this problem?
Thank you,
tandy

There’s only one keyboard so you should have keys = event.getKeys(‘t’,‘space’)

I personally wouldn’t even bother with ‘t’,‘space’ since other keys won’t do anything unless your code component directed them to.

1 Like