python-3.xmacoskeyboard

Key board module not working (python3, MacOSX, pycharmCE)


I am currently working on a program that will react to the pressing of a key. I am currently using the module "keyboard".

import keyboard

rk = keyboard.record(until='Esc')

keyboard.play(rk, speed_factor=1)

But when I run it, it gives me:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/user/PycharmProject/AUTOCLICKER/venv/lib/python3.8/site-packages/keyboard/__init__.py", line 294, in listen
    _os_keyboard.listen(self.direct_callback)
  File "/Users/user/PycharmProject/AUTOCLICKER/venv/lib/python3.8/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
    raise OSError("Error 13 - Must be run as administrator")
OSError: Error 13 - Must be run as administrator

What could I do to fix this? Is there any easier module to work with? thanks Triobro3


Solution

  • Run your script with administrator privileges with "sudo" command and see if it fixes your problem.