psychopy.org | Reference | Downloads | Github

The setting of event.globalKeys seems not take effect of the demo 'global_event_keys.py' in the coder view

I tried to run the demo ‘global_event_keys.py’ in the coder view. The window occurs correctly, but the setting of the event keys don’t take effect (the key was pressed but the related function didn’t be run). The version of PsychoPy is 1.90.1, and the version of Python is 3. They are run on win10.

I didn’t know that function, or the demo, existed. It’s very cool. It works for me on PsychoPy 1.90.1, Python 3 on a Mac.

I wonder if your window is selected and receiving the keyboard events? What happens if you edit the window creation line to look like this:

win = visual.Window(fullscr = True)

This problem may due to the Num Lock key. I turn it off and I try to run the script again. This time, it works.

You can also pass a modifier Numlock when you add a global key. So in addition to:
event.globalKeys.add("escape", func=core.quit)
you can also add this line:
event.globalKeys.add("escape", modifiers=['numlock'], func=core.quit)

This way you won’t need to worry about numlock.

1 Like