Keyboard API
Preview notice
The MatrixOS Python API is in preview and is subject to change; it may contain errors.
Overview
The HID Keyboard interface allows the device to emulate a standard USB keyboard, sending key press and release events to connected hosts. This enables text input, keyboard shortcuts, and comprehensive keyboard functionality.
The Python HID Keyboard API is implemented in Applications/Python/PikaPython/MatrixOS_HID_Keyboard.py with type hints in Applications/Python/PikaPython/_MatrixOS_HID_Keyboard.pyi.
MatrixOS.HID.Keyboard.Tap
def Tap(keycode: KeyboardKeycode, length_ms: int = 100) -> bool
Sends a complete keystroke (key press followed by key release) with configurable duration.
Parameters:
keycode(KeyboardKeycode): Key to press and releaselength_ms(int, optional): Duration to hold key in milliseconds (defaults to 100)
Returns:
bool: True if successful
MatrixOS.HID.Keyboard.Press
def Press(keycode: KeyboardKeycode) -> bool
Presses a key (key down event) without releasing it.
Parameters:
keycode(KeyboardKeycode): Key to press
Returns:
bool: True if successful
MatrixOS.HID.Keyboard.Release
def Release(keycode: KeyboardKeycode) -> bool
Releases a previously pressed key (key up event).
Parameters:
keycode(KeyboardKeycode): Key to release
Returns:
bool: True if successful
MatrixOS.HID.Keyboard.ReleaseAll
def ReleaseAll() -> None
Releases all currently pressed keys.
Keyboard Keycodes Reference
Common keyboard keycodes available in KeyboardKeycode:
Letters
KEY_AthroughKEY_Z: Letter keys
Numbers
KEY_1throughKEY_0: Number row keysKEY_KEYPAD_1throughKEY_KEYPAD_0: Numpad keys
Modifiers
KEY_LEFT_CTRL,KEY_RIGHT_CTRL: Control keysKEY_LEFT_SHIFT,KEY_RIGHT_SHIFT: Shift keysKEY_LEFT_ALT,KEY_RIGHT_ALT: Alt keysKEY_LEFT_GUI,KEY_RIGHT_GUI: Windows/Cmd keys
Special Keys
KEY_ENTER: Enter keyKEY_ESCAPE: Escape keyKEY_BACKSPACE: Backspace keyKEY_TAB: Tab keyKEY_SPACE: Space barKEY_DELETE: Delete key
Function Keys
KEY_F1throughKEY_F12: Function keys
Arrow Keys
KEY_RIGHT_ARROW,KEY_LEFT_ARROWKEY_DOWN_ARROW,KEY_UP_ARROW
Navigation Keys
KEY_PAGE_UP,KEY_PAGE_DOWNKEY_HOME,KEY_ENDKEY_INSERT
Media Keys (device dependent)
KEY_VOLUME_UP,KEY_VOLUME_DOWNKEY_MUTE
Punctuation
KEY_PERIOD,KEY_COMMAKEY_SEMICOLON,KEY_APOSTROPHEKEY_SLASH,KEY_BACKSLASHKEY_MINUS,KEY_EQUAL
Comments