Gamepad API
Preview notice
The MatrixOS Python API is in preview and is subject to change; it may contain errors.
Overview
The HID Gamepad interface allows the device to emulate a standard USB game controller, providing button controls, analog sticks, directional pad, and trigger functionality. This enables the device to work as a gamepad for gaming applications and other controller-aware software.
The Python HID Gamepad API is implemented in Applications/Python/PikaPython/MatrixOS_HID_Gamepad.py with type hints in Applications/Python/PikaPython/_MatrixOS_HID_Gamepad.pyi.
Button Functions
MatrixOS.HID.Gamepad.Press
def Press(button_id: int) -> None
Presses a gamepad button.
Parameters:
button_id(int): Button identifier (0-15 for standard gamepad buttons)
MatrixOS.HID.Gamepad.Release
def Release(button_id: int) -> None
Releases a gamepad button.
Parameters:
button_id(int): Button identifier to release
MatrixOS.HID.Gamepad.ReleaseAll
def ReleaseAll() -> None
Releases all currently pressed gamepad buttons.
MatrixOS.HID.Gamepad.Button
def Button(button_id: int, state: bool) -> None
Sets the state of a specific button.
Parameters:
button_id(int): Button identifierstate(bool): True to press, False to release
MatrixOS.HID.Gamepad.Buttons
def Buttons(button_mask: int) -> None
Sets multiple button states using a bitmask.
Parameters:
button_mask(int): Bitmask where each bit represents a button state
Analog Stick Functions
MatrixOS.HID.Gamepad.XAxis
def XAxis(value: int) -> None
Sets the left analog stick X-axis position.
Parameters:
value(int): Analog value (typically -32767 to 32767, 0 = center)
MatrixOS.HID.Gamepad.YAxis
def YAxis(value: int) -> None
Sets the left analog stick Y-axis position.
Parameters:
value(int): Analog value (typically -32767 to 32767, 0 = center)
MatrixOS.HID.Gamepad.ZAxis
def ZAxis(value: int) -> None
Sets the Z-axis (often used for left trigger).
Parameters:
value(int): Analog value
MatrixOS.HID.Gamepad.RXAxis
def RXAxis(value: int) -> None
Sets the right analog stick X-axis position.
Parameters:
value(int): Analog value (typically -32767 to 32767, 0 = center)
MatrixOS.HID.Gamepad.RYAxis
def RYAxis(value: int) -> None
Sets the right analog stick Y-axis position.
Parameters:
value(int): Analog value (typically -32767 to 32767, 0 = center)
MatrixOS.HID.Gamepad.RZAxis
def RZAxis(value: int) -> None
Sets the RZ-axis (often used for right trigger).
Parameters:
value(int): Analog value
Directional Pad Function
MatrixOS.HID.Gamepad.DPad
def DPad(direction: GamepadDPadDirection) -> None
Sets the directional pad (D-pad) direction.
Parameters:
direction(GamepadDPadDirection): D-pad direction
Gamepad D-Pad Directions
Available directions in GamepadDPadDirection:
NEUTRAL: No direction pressedUP: D-pad upDOWN: D-pad downLEFT: D-pad leftRIGHT: D-pad rightUP_LEFT: D-pad up-left diagonalUP_RIGHT: D-pad up-right diagonalDOWN_LEFT: D-pad down-left diagonalDOWN_RIGHT: D-pad down-right diagonal
Comments