the keyboard python library is not working on MacOS Mojave

187 Views Asked by At

When I run this code:

import keyboard

def function_that_checks_if_q_is_pressed():
    if keyboard.read_key()=="q":
        print(True)

while True:
    function_that_checks_if_q_is_pressed()
    if function_that_checks_if_q_is_pressed==True:
        break
    break

It gives me this error


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 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keyboard/__init__.py", line 294, in listen
    _os_keyboard.listen(self.direct_callback)
  File "/Library/Frameworks/Python.framework/Versions/3.8/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

On another thread, someone said to run the "sudo command" what does that mean?

Thank you

1

There are 1 best solutions below

0
On

The "sudo command" basically just runs a command as administrator You just type sudo followed by the command you would run In your case it looks like your program is trying to do something requiring administrator access When running your program try typing

 sudo python file.py

Hope this solves your problem :)