Title
• 1 min read
import keyboard
while True:
if keyboard.is_pressed("p"):
print("You pressed p")
break
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /home/dreamerblock/L/_notebooks/test.ipynb Cell 1 in <cell line: 4>() <a href='vscode-notebook-cell://wsl%2Bubuntu/home/dreamerblock/L/_notebooks/test.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a> import keyboard <a href='vscode-notebook-cell://wsl%2Bubuntu/home/dreamerblock/L/_notebooks/test.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2'>3</a> while True: ----> <a href='vscode-notebook-cell://wsl%2Bubuntu/home/dreamerblock/L/_notebooks/test.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3'>4</a> if keyboard.is_pressed("p"): <a href='vscode-notebook-cell://wsl%2Bubuntu/home/dreamerblock/L/_notebooks/test.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4'>5</a> print("You pressed p") <a href='vscode-notebook-cell://wsl%2Bubuntu/home/dreamerblock/L/_notebooks/test.ipynb#W1sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5'>6</a> break File ~/anaconda3/lib/python3.9/site-packages/keyboard/__init__.py:410, in is_pressed(hotkey) 402 def is_pressed(hotkey): 403 """ 404 Returns True if the key is pressed. 405 (...) 408 is_pressed('ctrl+space') #-> True 409 """ --> 410 _listener.start_if_necessary() 412 if _is_number(hotkey): 413 # Shortcut. 414 with _pressed_events_lock: File ~/anaconda3/lib/python3.9/site-packages/keyboard/_generic.py:35, in GenericListener.start_if_necessary(self) 33 try: 34 if not self.listening: ---> 35 self.init() 37 self.listening = True 38 self.listening_thread = Thread(target=self.listen) File ~/anaconda3/lib/python3.9/site-packages/keyboard/__init__.py:196, in _KeyboardListener.init(self) 195 def init(self): --> 196 _os_keyboard.init() 198 self.active_modifiers = set() 199 self.blocking_hooks = [] File ~/anaconda3/lib/python3.9/site-packages/keyboard/_nixkeyboard.py:113, in init() 112 def init(): --> 113 build_device() 114 build_tables() File ~/anaconda3/lib/python3.9/site-packages/keyboard/_nixkeyboard.py:109, in build_device() 107 global device 108 if device: return --> 109 ensure_root() 110 device = aggregate_devices('kbd') File ~/anaconda3/lib/python3.9/site-packages/keyboard/_nixcommon.py:174, in ensure_root() 172 def ensure_root(): 173 if os.geteuid() != 0: --> 174 raise ImportError('You must be root to use this library on linux.') ImportError: You must be root to use this library on linux.