My code calls waitKeys(…) to get keypresses and reaction times. 90% of the time it works perfectly, but occasionally when I launch it I get this (exactly this, not an infinite repetition):
PTB-WARNING: During PsychHID invocation: Some other running application is preventing me from accessing the keyboard/keypad/mouse/...!
PTB-WARNING: This is likely a security measure, e.g., to protect some active password entry field.
PTB-WARNING: Please identify and quit the offending application. E.g., some versions of Firefox are known to cause such problems...
PTB-WARNING: During PsychHID invocation: Some other running application is preventing me from accessing the keyboard/keypad/mouse/...!
PTB-WARNING: This is likely a security measure, e.g., to protect some active password entry field.
PTB-WARNING: Please identify and quit the offending application. E.g., some versions of Firefox are known to cause such problems...
PTB-WARNING: During PsychHID invocation: Some other running application is preventing me from accessing the keyboard/keypad/mouse/...!
PTB-WARNING: This is likely a security measure, e.g., to protect some active password entry field.
PTB-WARNING: Please identify and quit the offending application. E.g., some versions of Firefox are known to cause such problems...
PTB-WARNING: During PsychHID invocation: Some other running application is preventing me from accessing the keyboard/keypad/mouse/...!
PTB-WARNING: This is likely a security measure, e.g., to protect some active password entry field.
PTB-WARNING: Please identify and quit the offending application. E.g., some versions of Firefox are known to cause such problems...
PTB-WARNING: During PsychHID invocation: Some other running application is preventing me from accessing the keyboard/keypad/mouse/...!
PTB-WARNING: This is likely a security measure, e.g., to protect some active password entry field.
PTB-WARNING: Please identify and quit the offending application. E.g., some versions of Firefox are known to cause such problems...
and not surprisingly it does not respond to any of my keystrokes. Only to control-C.
I am only running Terminal (to launch the script), Xcode (to edit the python script), and Safari with only a couple of vanilla websites open (stackoverlow.com, discourse.psychopy.org, and google.com for searching). The only way I can stop this behaviour is by logging out then logging back in. Closing the Terminal window and opening a new one doesn’t fix it. Quitting from Terminal and relaunching it doesn’t fix it. Quitting from all running apps doesn’t fix it.
Sometimes that it happens, I had just control-C’d out of the app just prior to this happening on the next launch. So perhaps Psychopy is leaving some orphaned thread still running in the background, from that prior invocation of the script, and that thread hasn’t relinquished its claim on the keyboard? How could I find out? And how can I address that in my code?
Here’s the relevant code:
**from** psychopy **import** prefs
prefs.hardware['audioLib'] = ['PTB'] # Prepare to use the right audio backend before importing sound
latencyMode = 4 # For PTB. 0, 1, 2, 3, 4
prefs.hardware['audioLatencyMode'] = [str(latencyMode)]
**from** psychopy.sound.backend_ptb **import** SoundPTB
**from** psychopy.hardware **import** keyboard
kb = keyboard.Keyboard() # Set up a keyboard device
targetAudio = SoundPTB(listFiles[thisAudioIndex])
targetAudio.play()
keys = kb.waitKeys(keyList = ["return", "space", "down", "right"],
waitRelease=False)
targetAudio.stop()
2017 MacBook Pro, using the inbuilt keyboard. macOS 11.4, Python 3.8
I also posted this on stackoverflow.com.