Intermittent: PTB-WARNING: During PsychHID invocation: Some other running application is preventing me from accessing the keyboard/keypad/mouse/...!

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.

Have a look at slide 20 of my PsychoPy Primer slides for how to enable input monitoring on a Mac.

Thanks so much for the quick response! It is true that I would have encountered similar messages if I had not enabled keyboard access in the Privacy prefs. However in the current case that isn’t the problem because this seems to be intermittent. I had enabled access to the keyboard when Infirst started this project a few weeks ago. My earlier. versions of my Python/PsychoPy code successfully and consistently enabled me to measure keystrokes, but these warnings have only started a few days ago, and only happen about 10% of the times that I launch my script. I fear there is something else going on in my case.

I ran into this issue as well with intermittent errors (even after confirming the Security & Privacy settings were correct), and simply restarting my mac seems to have fixed the issue

1 Like