Open
Description
When using a HID keyboard and the code stops (crash, end code or reload) while a key is pressed, the key will remain pressed until the board is fully reset, or the code happens to release_all() or something similar.
Is it possible to "empty" the HID output reports on code end ?
Such a script will hold the space key until the board is reset.
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
keyboard = Keyboard(usb_hid.devices)
keyboard.press(Keycode.SPACE)
Using atexit is a python solution.
import atexit
import time
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
keyboard = Keyboard(usb_hid.devices)
atexit.register(keyboard.release_all)
keyboard.press(Keycode.SPACE)
time.sleep(1) # a few spaces will appear based on your OS's key repeat settings