I'm trying to close my program when the esc key is pressed. For this I found the keyboard library.
import keyboard #pip install keyboard
t=0
while True:
print (t)
t=t+1
if keyboard.is_pressed('esc'):
print('STOP prog')
break
In windows (pycharm) works perfect. But when I do it with my raspberry appears this error.
Traceback (most recent call last):
File "/home/pi/Miguel/thesis/face_detection_applicationv2.py", line 151, in <module>
main()
File "/home/pi/Miguel/thesis/face_detection_applicationv2.py", line 137, in main
if keyboard.is_pressed('esc'):
File "/usr/local/lib/python3.5/dist-packages/keyboard/__init__.py", line 408, in is_pressed
_listener.start_if_necessary()
File "/usr/local/lib/python3.5/dist-packages/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/usr/local/lib/python3.5/dist-packages/keyboard/__init__.py", line 194, in init
_os_keyboard.init()
File "/usr/local/lib/python3.5/dist-packages/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/usr/local/lib/python3.5/dist-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/usr/local/lib/python3.5/dist-packages/keyboard/_nixcommon.py", line 174, in ensure_root
raise ImportError('You must be root to use this library on linux.')
**ImportError: You must be root to use this library on linux.**
Somebody knows why is happening this?
If I do pip list
keyboard appears.
sudo python yourprogram.py
on RPi? – Ephemeral Jul 8 '19 at 8:16