libretro.drivers.input.iterable

InputDriver implementation that replays an iterable of input states.

See also

InputDriver

The protocol this driver implements.

Classes

Direction

Cardinal direction used to match against directional buttons across device types.

IterableInputDriver

InputDriver that replays input states drawn from an iterable source.

Point

A 2D integer coordinate, used for pointer and light-gun positions.

PortState

Aggregation of all input device state for a given port.

class IterableInputDriver[source]

Bases: InputDriver

InputDriver that replays input states drawn from an iterable source.

Each call to poll() advances one step through the supplied source, making it convenient to script deterministic input sequences for tests.

__init__(input_generator=None, device_capabilities=<InputDeviceFlag.ALL: 126>, bitmasks_supported=True, max_users=8)[source]

Construct the driver with optional input source and capability flags.

Parameters:
classmethod __new__(*args, **kwargs)
keyboard_event(down, keycode, character, modifiers)

Forward a keyboard event to the registered keyboard_callback, if any.

Parameters:
  • down (bool) – True for key-down, False for key-up.

  • keycode (Key) – The libretro key identifier.

  • character (int | str | bytes) – The Unicode codepoint (or encoded form) produced by the key, for keys that produce text.

  • modifiers (KeyModifier) – Bitmask of active modifier keys at the time of the event.

Return type:

None

property device_capabilities

Bitmask of input device classes supported by this driver.

Returned to the core in response to RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES. None if the driver does not advertise device capabilities.

Parameters:

capabilities – The capability bitmask to advertise.

Raises:

UnsupportedEnvCall – If this driver does not advertise device capabilities.

See also

InputDeviceFlag

The bit flags that compose this bitmask.

property bitmasks_supported

Whether the driver supports the joypad-bitmask state encoding.

Returned to the core in response to RETRO_ENVIRONMENT_GET_INPUT_BITMASKS. None if the driver does not advertise bitmask support either way.

Parameters:

bitmask_supportedTrue if the driver supports joypad bitmasks.

Raises:

UnsupportedEnvCall – If this driver does not advertise bitmask support.

property max_users

The maximum number of input ports this driver advertises to the core.

Returned to the core in response to RETRO_ENVIRONMENT_GET_INPUT_MAX_USERS. None if the driver does not advertise a maximum.

Parameters:

max_users – The maximum number of input ports to advertise.

Raises:

UnsupportedEnvCall – If this driver does not advertise a maximum.

poll()[source]

Sample fresh input state for the upcoming frame.

Called by the session once per frame before the core’s Core.run() so subsequent state() queries see consistent input.

See also

retro_input_poll_t

The C function pointer type whose signature this method implements.

Return type:

None

state(port, device, index, id)[source]

Return the current state of a single input control.

Parameters:
  • port (Port (int)) – The input port being queried.

  • device (int) – The input device class registered to port.

  • index (int) – Sub-device index (e.g. analog stick number).

  • _id – Button or axis identifier within the device class.

Return type:

int

Returns:

The control’s current state, encoded per libretro’s input conventions.

See also

retro_input_state_t

The C function pointer type whose signature this method implements.

property descriptors

The input descriptors registered by the core, if any.

Set by the core via RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS to advertise the buttons and axes it actually consumes.

Parameters:

descriptors – The sequence of descriptors registered by the core.

Raises:

UnsupportedEnvCall – If this driver does not accept input descriptors.

See also

retro_input_descriptor

The C struct that this attribute holds.

property controller_info

Per-port controller descriptions registered by the core, if any.

Set by the core via RETRO_ENVIRONMENT_SET_CONTROLLER_INFO to advertise the controllers each port can be configured to emulate.

Parameters:

info – The controller descriptions registered by the core.

Raises:

UnsupportedEnvCall – If this driver does not accept controller info.

See also

retro_controller_description

The C struct that this attribute holds.

property keyboard_callback

The keyboard callback registered by the core, if any.

Set by the core via RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK to receive key-down/key-up events. None if the core has not registered a keyboard callback.

Parameters:

callback – The callback to register.

Raises:

UnsupportedEnvCall – If this driver does not support keyboard input.

See also

retro_keyboard_callback

The C struct registered by the core that contains this callback.

class Direction[source]

Bases: Enum

Cardinal direction used to match against directional buttons across device types.

RIGHT = 1
UP = 2
LEFT = 3
DOWN = 4
matches_direction(other)[source]

Return True if the given device input matches this direction.

Return type:

bool

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.

classmethod iter(self)

Return members in definition order.

classmethod len(self)

Return the number of members (no aliases)

class PortState[source]

Bases: object

Aggregation of all input device state for a given port.

joypad
mouse
keyboard
light_gun
analog
pointer
self[item][source]
Overloads:
  • self, item (Literal[InputDevice.NONE]) → None

  • self, item (Literal[InputDevice.JOYPAD]) → JoypadState | None

  • self, item (Literal[InputDevice.MOUSE]) → MouseState | None

  • self, item (Literal[InputDevice.KEYBOARD]) → KeyboardState | None

  • self, item (Literal[InputDevice.LIGHTGUN]) → LightGunState | None

  • self, item (Literal[InputDevice.ANALOG]) → AnalogState | None

  • self, item (Literal[InputDevice.POINTER]) → PointerState | None

Return the state of a particular device on this port.

__init__(joypad=None, mouse=None, keyboard=None, light_gun=None, analog=None, pointer=None)
classmethod __new__(*args, **kwargs)
class Point[source]

Bases: object

A 2D integer coordinate, used for pointer and light-gun positions.

x
y
__init__(x=0, y=0)
classmethod __new__(*args, **kwargs)