KeyPad API
Preview notice
The MatrixOS Python API is in preview and is subject to change; it may contain errors.
Overview
The KeyPad system in MatrixOS provides access to the 8x8 pressure-sensitive keypad input. It handles key events, pressure levels, and coordinate mapping between the physical keys and LED matrix. The KeyPad API is available as MatrixOS.KeyPad and is imported by default.
The API returns KeyEvent objects containing information about key presses, releases, and hold states, along with pressure data for pressure-sensitive devices.
The Python KeyPad API is implemented in Applications/Python/PikaPython/MatrixOS_MatrixOS.KeyPad.py with type hints in Applications/Python/PikaPython/_MatrixOS_MatrixOS.KeyPad.pyi.
Constants
The KeyPad API uses the following predefined constants:
FunctionKeyID = 0- Refers to the default key ID of the function key
MatrixOS.KeyPad.Get
def Get(timeout_ms: int = 0) -> any
Gets the next key event from the input queue.
Parameters:
timeout_ms(int, optional): Timeout in milliseconds to wait for input (defaults to 0 for no timeout)
Returns:
KeyEvent: Key event object on successNone: On timeout or no input available
MatrixOS.KeyPad.GetKey
def GetKey(keyXY: Point) -> any
Gets the current state of a specific key by coordinates.
Parameters:
keyXY(Point): Key coordinates (0-7 for both x and y)
Returns:
KeyInfo: Key information object if valid positionNone: If invalid coordinates
MatrixOS.KeyPad.GetKeyByID
def GetKeyByID(keyID: int) -> any
Gets the current state of a specific key by ID.
Parameters:
keyID(int): Key ID (0-63 for 8x8 matrix)
Returns:
KeyInfo: Key information object if valid IDNone: If invalid key ID
MatrixOS.KeyPad.Clear
def Clear() -> None
Clears the key event queue, discarding any pending events.
MatrixOS.KeyPad.XY2ID
def XY2ID(xy: Point) -> int
Converts key coordinates to key ID.
Parameters:
xy(Point): Key coordinates
Returns:
int: Key ID (0-63), or -1 if invalid coordinates
MatrixOS.KeyPad.ID2XY
def ID2XY(keyID: int) -> any
Converts key ID to coordinates.
Parameters:
keyID(int): Key ID (0-63)
Returns:
Point: Key coordinates if valid IDNone: If invalid key ID
Comments