event.globalKey.add does not end program

I’m currently running into a problem with ending my program with a key combination.
I’ve tried the example program given with globalKey documentation but i couldn’t get this to work. Here is the part which fails:
event.globalKeys.add(key=‘q’, modifiers=[‘ctrl’], func=core.quit)

everytime I press ctrl + q the following is displayed on the terminal:
Exception ignored on calling ctypes callback function…

I’m new to Psychopy and maybe this is a problem with me, but i’ve tried it on two other devices an nowhere did this method work…
Thanks in advanced for your time

I don’t know why it’s failing but I have a few guesses, and there are some things you can try to narrow it down. My guesses in order of likelihood:

  1. Calling core.quit() this way is failing for some reason. You can test this by replacing core.quit with another function (a dummy function that presents some text or something) and seeing if you get the same error. If you don’t, you could try making a new function that called core.quit for you, like so:
def onGlobalKey():
  1. If changing the function doesn’t do anything, then it could be something about the key + modifier combo, and that’s interacting with globalKeys in some weird way. Easy test: Take out the modifier argument and see if just pressing “q” throws the same error.

  2. If the two tests above won’t change anything it might be an issue with globalKeys itself, and you’ll just need to put a check for this key in all of your routines/loops. Why that might be the case I have no idea, but the simple solution is just whenever you call event.getKeys() check if it’s the key you care about and quit if so.

1 Like

Hey, I’ve tried the first two methods and both failed…
Thats why I’ve implemented your last solution and got it to work.
Soooo thank you!

Never the less, I think that there is a problem with the add Method and or global keys. Does the program/method work on your device?
Also, because it ignores the ctypes callback funktion, could it be a issue with the ctypes libary?