HID API
Overviewβ
MatrixOS.HID exposes keyboard, gamepad, and RawHID helpers.
Use press(...) and release(...) when the key or button should stay active across multiple loop iterations. Use tap(...) for a short press-and-release action.
MatrixOS.HID.Keyboard.tapβ
tap(keycode: int, length_ms: int = 100) -> bool
Presses and releases one keyboard key.
Parameters:
keycode: USB HID keyboard keycode.length_ms: Press duration in milliseconds.
Returns:
bool:Truewhen the tap was sent.
MatrixOS.HID.Keyboard.pressβ
press(keycode: int) -> bool
Presses one keyboard key and leaves it held.
Parameters:
keycode: USB HID keyboard keycode.
Returns:
bool:Truewhen the press was sent.
MatrixOS.HID.Keyboard.releaseβ
release(keycode: int) -> bool
Releases one keyboard key.
Parameters:
keycode: USB HID keyboard keycode.
Returns:
bool:Truewhen the release was sent.
MatrixOS.HID.Keyboard.release_allβ
release_all() -> None
Releases all pressed keyboard keys.
MatrixOS.HID.Gamepad.tapβ
tap(button_id: int, length_ms: int = 100) -> None
Presses and releases one gamepad button.
Parameters:
button_id: Gamepad button ID.length_ms: Press duration in milliseconds.
MatrixOS.HID.Gamepad.pressβ
press(button_id: int) -> None
Presses one gamepad button and leaves it held.
Parameters:
button_id: Gamepad button ID.
MatrixOS.HID.Gamepad.releaseβ
release(button_id: int) -> None
Releases one gamepad button.
Parameters:
button_id: Gamepad button ID.
MatrixOS.HID.Gamepad.release_allβ
release_all() -> None
Releases all gamepad buttons.
MatrixOS.HID.Gamepad.buttonβ
button(button_id: int, state: bool) -> None
Sets one gamepad button state.
Parameters:
button_id: Gamepad button ID.state:Truefor pressed,Falsefor released.
MatrixOS.HID.Gamepad.buttonsβ
buttons(button_mask: int) -> None
Sets all gamepad button states from a bitmask.
Parameters:
button_mask: Bitmask of pressed buttons.
MatrixOS.HID.Gamepad.x_axisβ
x_axis(value: int) -> None
Sets the gamepad X axis.
Parameters:
value: Axis value. Values are clamped to-32768..32767.
MatrixOS.HID.Gamepad.y_axisβ
y_axis(value: int) -> None
Sets the gamepad Y axis.
Parameters:
value: Axis value. Values are clamped to-32768..32767.
MatrixOS.HID.Gamepad.z_axisβ
z_axis(value: int) -> None
Sets the gamepad Z axis.
Parameters:
value: Axis value. Values are clamped to-32768..32767.
MatrixOS.HID.Gamepad.rx_axisβ
rx_axis(value: int) -> None
Sets the gamepad RX axis.
Parameters:
value: Axis value. Values are clamped to-32768..32767.
MatrixOS.HID.Gamepad.ry_axisβ
ry_axis(value: int) -> None
Sets the gamepad RY axis.
Parameters:
value: Axis value. Values are clamped to-32768..32767.
MatrixOS.HID.Gamepad.rz_axisβ
rz_axis(value: int) -> None
Sets the gamepad RZ axis.
Parameters:
value: Axis value. Values are clamped to-32768..32767.
MatrixOS.HID.Gamepad.dpadβ
dpad(direction: int) -> None
Sets the gamepad D-pad direction.
Parameters:
direction: Gamepad D-pad direction value.
MatrixOS.HID.RawHID.getβ
get(timeout_ms: int = 0) -> bytes | None
Reads one RawHID report.
Parameters:
timeout_ms: Maximum time to wait in milliseconds.0is non-blocking.
Returns:
bytes | None: Report bytes, orNonewhen no report is available.
MatrixOS.HID.RawHID.sendβ
send(data: bytes) -> bool
Sends one RawHID report.
Parameters:
data: Report bytes.
Returns:
bool:Truewhen sent.
Keyboard And Gamepad Examplesβ
import MatrixOS
# Tap sends a press and release for a simple one-shot action.
MatrixOS.HID.Keyboard.tap(0x04) # HID keycode for "a"
MatrixOS.HID.Gamepad.tap(1)
RawHID Echo Exampleβ
import MatrixOS
# Poll once without blocking. Use a timeout if the app should wait.
report = MatrixOS.HID.RawHID.get(0)
if report:
# Echo the exact report bytes back to the host.
MatrixOS.HID.RawHID.send(report)
This echo pattern is useful for a custom host protocol.
Comments