SDL Joystick Support tcod.sdl.joystick

SDL Joystick Support.

Added in version 13.8.

class tcod.sdl.joystick.ControllerAxis(value)[source]

The standard axes for a game controller.

LEFTX = 0
LEFTY = 1
RIGHTX = 2
RIGHTY = 3
TRIGGERLEFT = 4
TRIGGERRIGHT = 5
class tcod.sdl.joystick.ControllerButton(value)[source]

The standard buttons for a game controller.

A = 0
B = 1
BACK = 4
DPAD_DOWN = 12
DPAD_LEFT = 13
DPAD_RIGHT = 14
DPAD_UP = 11
GUIDE = 5
LEFTSHOULDER = 9
LEFTSTICK = 7
MISC1 = 15
PADDLE1 = 16
PADDLE2 = 17
PADDLE3 = 18
PADDLE4 = 19
RIGHTSHOULDER = 10
RIGHTSTICK = 8
START = 6
TOUCHPAD = 20
X = 2
Y = 3
class tcod.sdl.joystick.GameController(sdl_controller_p: Any)[source]

A standard interface for an Xbox 360 style game controller.

__eq__(other: object) bool[source]

Return True if self and other are both controllers referring to the same joystick.

__hash__() int[source]

Return the joystick id as a hash.

get_axis(axis: ControllerAxis) int[source]

Return the state of the given axis.

The state is usually a value from -32768 to 32767, with positive values towards the lower-right direction. Triggers have the range of 0 to 32767 instead.

get_button(button: ControllerButton) bool[source]

Return True if button is currently held.

joystick: Final

The Joystick associated with this controller.

class tcod.sdl.joystick.Joystick(sdl_joystick_p: Any)[source]

A low-level SDL joystick.

__eq__(other: object) bool[source]

Return True if self and other refer to the same joystick.

__hash__() int[source]

Return the joystick id as a hash.

get_axis(axis: int) int[source]

Return the raw value of axis in the range -32768 to 32767.

get_ball(ball: int) tuple[int, int][source]

Return the values (delta_x, delta_y) of ball since the last poll.

get_button(button: int) bool[source]

Return True if button is currently held.

get_hat(hat: int) tuple[Literal[-1, 0, 1], Literal[-1, 0, 1]][source]

Return the direction of hat as (x, y). With (-1, -1) being in the upper-left.

axes: Final[int]

The total number of axes.

balls: Final[int]

The total number of trackballs.

buttons: Final[int]

The total number of buttons.

guid: Final[str]

The GUID of this joystick.

hats: Final[int]

The total number of hats.

id: Final[int]

The instance ID of this joystick. This is not the same as the device ID.

name: Final[str]

The name of this joystick.

sdl_joystick_p: Final

The CFFI pointer to an SDL_Joystick struct.

tcod.sdl.joystick.controller_event_state(new_state: bool | None = None) bool[source]

Check or set game controller event polling.

tcod.sdl.joystick.get_controllers() list[GameController][source]

Return a list of all connected game controllers.

This ignores joysticks without a game controller mapping.

tcod.sdl.joystick.get_joysticks() list[Joystick][source]

Return a list of all connected joystick devices.

tcod.sdl.joystick.init() None[source]

Initialize SDL’s joystick and game controller subsystems.

tcod.sdl.joystick.joystick_event_state(new_state: bool | None = None) bool[source]

Check or set joystick event polling.