I'm coding in python in Mu in Ubuntu linux.
This is the error it gives me when using a provided example code in the module's API:
Traceback (most recent call last):
File "/home/pi/mu_code/keyboard/keyboard.py", line 3, in <module>
import keyboard
File "/home/pi/mu_code/keyboard/keyboard.py", line 11, in <module>
keyboard.hook(print_pressed_keys)
AttributeError: module 'keyboard' has no attribute 'hook'
Example code being used:
"""
Prints the scan code of all currently pressed keys.
Updates on every keyboard event.
"""
import sys
sys.path.append('..')
import keyboard
def print_pressed_keys(e):
line = ', '.join(str(code) for code in keyboard._pressed_events)
# '\r' and end='' overwrites the previous line.
# ' '*40 prints 40 spaces at the end to ensure the previous line is cleared.
print('\r' + line + ' '*40, end='')
keyboard.hook(print_pressed_keys)
keyboard.wait()
I'm not sure why this is occuring, I've tried to delete and install it multiple times using the command, pip install keyboard, and it works in installing it. It seems like my IDE just doesn't recognize it.