libretro.api.input.device

Input device definitions and state callbacks.

Module Attributes

Port

A controller port index.

retro_input_poll_t

Poll input devices for the current frame.

retro_input_state_t

Query the state of a specific input on a controller.

Functions

RETRO_DEVICE_SUBCLASS(base, id)

Generate an ID for a libretro input device subclass.

Classes

InputDevice

Enumeration of standard input device types.

InputDeviceFlag

Bitmask flag equivalent of InputDevice.

InputDeviceState

Empty marker class for identifying input device states.

retro_controller_description

Description of a specific kind of controller emulated by a core.

retro_controller_info

List of controller types usable by a controller port.

retro_input_descriptor

Description of a single input action for a given device.

class InputDeviceFlag[source]

Bases: IntFlag

Bitmask flag equivalent of InputDevice.

>>> from libretro.api.input import InputDeviceFlag
>>> InputDeviceFlag.JOYPAD
<InputDeviceFlag.JOYPAD: 2>
NONE = 1
JOYPAD = 2
MOUSE = 4
KEYBOARD = 8
LIGHTGUN = 16
ANALOG = 32
POINTER = 64
ALL = 126
__new__(value)
other in self

Returns True if self has at least the same flags set as other.

iter(self)

Returns flags in definition order.

len(self)

Return the number of members (no aliases)

classmethod self[name]

Return the member matching name.

__init__()
class InputDevice[source]

Bases: IntEnum

Enumeration of standard input device types.

Corresponds to the RETRO_DEVICE_* constants in libretro.h.

>>> from libretro.api.input import InputDevice
>>> InputDevice.JOYPAD
<InputDevice.JOYPAD: 1>
NONE = 0
JOYPAD = 1
MOUSE = 2
KEYBOARD = 3
LIGHTGUN = 4
ANALOG = 5
POINTER = 6
property flag

Returns the corresponding InputDeviceFlag for this device.

__new__(value)
classmethod value in self

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod self[name]

Return the member matching name.

__init__()
classmethod iter(self)

Return members in definition order.

classmethod len(self)

Return the number of members (no aliases)

RETRO_DEVICE_SUBCLASS(base, id)[source]

Generate an ID for a libretro input device subclass.

Return type:

int

retro_input_poll_t

Poll input devices for the current frame.

Registered by the frontend and called by the core at least once per retro_run() to refresh cached input state before any calls to retro_input_state_t.

Corresponds to retro_input_poll_t in libretro.h.

See also

InputDriver.poll

The InputDriver method that implements this callback.

Core.set_input_poll

The method that exposes this callback to a core.

retro_input_state_t

Query the state of a specific input on a controller.

Registered by the frontend and called by the core to read the most recently polled input.

Parameters:
  • port – Index of the controller port to query.

  • device – One of the InputDevice constants identifying the abstract device type. The value is masked with RETRO_DEVICE_MASK.

  • index – Sub-index whose meaning depends on device (e.g. an analog stick index).

  • id – Identifier of the specific input to read, such as one of the RETRO_DEVICE_ID_* constants.

Returns:

The current input value; semantics depend on device and id, and 0 is returned for unsupported combinations.

Corresponds to retro_input_state_t in libretro.h.

See also

InputDriver.state

The suggested entry point for this callback in libretro.py.

Core.set_input_state

The method that exposes this callback to a core.

class retro_input_descriptor[source]

Bases: Structure

Description of a single input action for a given device.

Corresponds to retro_input_descriptor in libretro.h.

port

Controller port index.

device

Input device type.

index

Sub-device index (e.g. analog stick index).

id

Button or axis identifier.

description

Human-readable label for this input.

__deepcopy__(_)[source]

Return a deep copy of this object, including all strings.

Intended for use with copy.deepcopy().

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
class retro_controller_description[source]

Bases: Structure

Description of a specific kind of controller emulated by a core.

Corresponds to retro_controller_description in libretro.h.

desc

Human-readable name of the controller type.

id

Device type identifier, used with retro_set_controller_port_device().

__deepcopy__(_)[source]

Create a deep copy of this object, including all strings. Intended for use with copy.deepcopy().

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
class retro_controller_info[source]

Bases: Structure

List of controller types usable by a controller port.

Can be indexed like a Sequence to access individual retro_controller_descriptions.

Corresponds to retro_controller_info in libretro.h.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
types

Array of controller types supported by this port.

num_types

Number of entries in types.

__deepcopy__(memo)[source]

Return a deep copy of this object, including all strings and arrays. Intended for use with copy.deepcopy().

self[index][source]
Overloads:
  • self, index (int) → retro_controller_description

  • self, index (slice[retro_controller_description]) → list[retro_controller_description]

Return the retro_controller_description at the given index or slice.

Parameters:

index – An integer index or slice object.

Returns:

A single retro_controller_description if index is an int, or a list of them if it’s a slice.

Raises:
len(self)[source]

Return the number of device types.

Returns:

num_types.

class InputDeviceState[source]

Bases: object

Empty marker class for identifying input device states.

__init__()
classmethod __new__(*args, **kwargs)
class Port

A controller port index.

Intended for type safety when working with controller ports.

alias of int

self(x, /)
__init__(name, tp)