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