USB HID keyboard device that runs alongside the built-in CDC (serial) interface.
Builds a composite USB descriptor by appending a HID keyboard interface to the existing CDC configuration so both the REPL serial port and the keyboard are available at the same time.
| Method | __init__ |
Create a USBKeyboard instance. |
| Method | init |
Initialise and activate the composite CDC + HID USB device. |
| Method | press |
Press and immediately release a key. |
| Method | release |
Send an all-zeros HID report to release all currently held keys. |
| Method | send |
Send a single HID key-down report without releasing the key. |
| Method | shortcut |
Press a key combination and wait briefly after releasing. |
| Method | type |
Type a string by pressing each character in sequence. |
| Constant | HID |
Undocumented |
| Constant | HID |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEY |
Undocumented |
| Constant | KEYMAP |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | MOD |
Undocumented |
| Constant | SHIFT |
Undocumented |
| Method | _on |
Control-transfer callback invoked by the USB stack for HID class requests. |
| Method | _on |
Transfer-complete callback invoked by the USB stack. |
| Method | _wait |
Block until the previous HID transfer completes or the timeout expires. |
| Instance Variable | _manufacturer |
Undocumented |
| Instance Variable | _product |
Undocumented |
| Instance Variable | _serial |
Undocumented |
| Instance Variable | _usbdev |
Undocumented |
| Instance Variable | _xfer |
Undocumented |
Create a USBKeyboard instance.
| Parameters | |
manufacturer:str | Manufacturer string in the USB device descriptor. Defaults to "MicroPython". |
product:str | Product string in the USB device descriptor. Defaults to "Picoware Keyboard". |
serial:str | Serial number string in the USB device descriptor. Defaults to "000000". |
Initialise and activate the composite CDC + HID USB device.
Appends a HID keyboard interface to the built-in CDC descriptor, re-configures the USBDevice, and activates it. Must be called once before any key-sending methods are used.
Press and immediately release a key.
| Parameters | |
modifier:int | Modifier byte (e.g. MOD_LSHIFT, MOD_LCTRL). Defaults to 0. |
keycode:int | HID usage-ID of the key to press. Defaults to 0. |
Send a single HID key-down report without releasing the key.
| Parameters | |
modifier:int | Modifier byte (e.g. MOD_LSHIFT, MOD_LCTRL). Defaults to 0. |
keycode:int | HID usage-ID of the key to press. Defaults to 0. |
Press a key combination and wait briefly after releasing.
Useful for OS-level shortcuts where a short post-press delay ensures the host has time to process the keystroke.
| Parameters | |
modifier:int | Modifier byte (e.g. MOD_LGUI, MOD_LCTRL). |
keycode:int | HID usage-ID of the key to press. |
delayint | Milliseconds to sleep after the key is released. Defaults to 100. |
Type a string by pressing each character in sequence.
Characters in SHIFT_CHARS are sent with the left-shift modifier. Characters not found in KEYMAP are silently skipped.
| Parameters | |
s:str | The string to type. |
delayint | Milliseconds to wait between each keystroke. Defaults to 50. |
Control-transfer callback invoked by the USB stack for HID class requests.
Handles GET_DESCRIPTOR (HID report descriptor), SET_IDLE / SET_PROTOCOL, and GET_PROTOCOL requests required by the HID class specification.
| Parameters | |
stage:int | Transfer stage (1 = SETUP, 3 = ACK). |
request:bytes | Raw 8-byte SETUP packet. |
| Returns | |
bytes, bool | Requested data, True to ACK with no data, or False to stall. |
Transfer-complete callback invoked by the USB stack.
Sets _xfer_done when the HID IN endpoint (0x83) finishes so that _wait can unblock.
| Parameters | |
ep:int | Endpoint address that completed the transfer. |
res:int | Result code from the USB stack. |
numint | Number of bytes transferred. |