当我在 Mac 上的 Jupyter Notebook 中运行以下代码时
import keyboard
if keyboard.is_pressed('q'):
print("Yes")
它显示以下错误:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/site-packages/keyboard/__init__.py", line 294, in listen
_os_keyboard.listen(self.direct_callback)
File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/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
由于在 MacOS 上,以管理员身份运行选项不像 Windows 那样可用,我该怎么办?我想检测按键,就像按下键盘上的任意键一样,程序停止!
I have also tried to run the above code through my terminal in iPython. It shows the same error there too.