How to make Changes Allowed keys in routines

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win11
PsychoPy version (e.g. 1.84.x): v2023.2.2
Standard Standalone? (y/n) If not then what?:Y

[keyboard component]

[condition file]


I want to modify the keys that can be input from the keyboard depending on the image displayed on the screen. I’m trying to use the condition file to use the allowed keys part as a variable, but I keep getting errors. Is there a solution to this problem?

I think this is a bug to do with namespaces - essentially, because the Keyboard Component is using the variable for allowedKeys, it’s classed as “local” to the experiment’s run function, but when loaded from a spreadsheet it’s read in as a “global” variable. I’ll figure out a fix for this for the next bug fix release, in the meantime you should be able to do:

global interkey


interkey = globals()['interkey']

in the Begin Routine tab of a Code Component to fix the problem (basically just forces Python to use the value from the spreadsheet rather than keeping it undefined)

1 Like