Skip to main content
Version: Matrix OS 3.2

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 identifier
  • state (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 pressed
  • UP: D-pad up
  • DOWN: D-pad down
  • LEFT: D-pad left
  • RIGHT: D-pad right
  • UP_LEFT: D-pad up-left diagonal
  • UP_RIGHT: D-pad up-right diagonal
  • DOWN_LEFT: D-pad down-left diagonal
  • DOWN_RIGHT: D-pad down-right diagonal

Comments