Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup HID reports on script end ? #7535

Open
Neradoc opened this issue Feb 1, 2023 · 0 comments
Open

Cleanup HID reports on script end ? #7535

Neradoc opened this issue Feb 1, 2023 · 0 comments

Comments

@Neradoc
Copy link

Neradoc commented Feb 1, 2023

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
@tannewt tannewt added the usb label Feb 1, 2023
@tannewt tannewt added this to the Long term milestone Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants