Allowed Keys not accessible from code component?

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 3.0.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

In the decision component I select two buttons (i.e. ‘up’, ‘space’) as allowed keys, as shown below:

I then code some actions based on pressing those keys:

The problem:

The code only works if the keys referenced in the code component are not the same as those in the allowed keys. For example, if put ‘a’, ‘r’ in the allowed keys, then the code with ‘up’ and ‘space’ in the code components behaves as expected when pressing up or space. But of course then the response doesn’t get recorded in the response file. With ‘up’ and ‘space’ in the allowed keys then the response is recorded in the response file but the behaviour coded for in the code component doesn’t run.

The same is true if I have allowed keys set as constant or set on every repeat.

This is driving me nuts. Any help would be appreciated.

Cheers.

This is because you are using both event module, and the keyboard component. You should stick with one or the other. If you want to stick with the keyboard component, then use the following instead:

if decision.keys == 'up':
    # do your if statements...
elif decision.keys == 'space':
    # do your if statements...

If you want to use the event module, you would have to delete the keyboard component and the code would be ok, but you would have to manually code to save your responses etc.

1 Like