libretro.drivers.input.iterable¶
InputDriver implementation that replays an iterable of input states.
See also
InputDriverThe protocol this driver implements.
Classes
Cardinal direction used to match against directional buttons across device types. |
|
|
|
A 2D integer coordinate, used for pointer and light-gun positions. |
|
Aggregation of all input device state for a given port. |
- class IterableInputDriver[source]¶
Bases:
InputDriverInputDriverthat 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:
input_generator (
Callable[[],Iterator[PortState|JoypadState|MouseState|KeyboardState|LightGunState|AnalogState|PointerState|Point|Pointer|bool|int|None|Sequence[PortState|JoypadState|MouseState|KeyboardState|LightGunState|AnalogState|PointerState|Point|Pointer|bool|int|None]]] |Iterable[PortState|JoypadState|MouseState|KeyboardState|LightGunState|AnalogState|PointerState|Point|Pointer|bool|int|None|Sequence[PortState|JoypadState|MouseState|KeyboardState|LightGunState|AnalogState|PointerState|Point|Pointer|bool|int|None]] |Iterator[PortState|JoypadState|MouseState|KeyboardState|LightGunState|AnalogState|PointerState|Point|Pointer|bool|int|None|Sequence[PortState|JoypadState|MouseState|KeyboardState|LightGunState|AnalogState|PointerState|Point|Pointer|bool|int|None]] |None) – A generator function, iterable, or iterator that yields per-frame input poll results.Noneproduces no input.device_capabilities (
InputDeviceFlag|None) – Bitmask of supported device kinds.bitmasks_supported (
bool|None) – Whether the joypad bitmask query is supported.max_users (
int|None) – Maximum number of controller ports.
- classmethod __new__(*args, **kwargs)¶
- keyboard_event(down, keycode, character, modifiers)¶
Forward a keyboard event to the registered
keyboard_callback, if any.- Parameters:
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:
- 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.Noneif 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
InputDeviceFlagThe 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.Noneif the driver does not advertise bitmask support either way.- Parameters:
bitmask_supported –
Trueif 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.Noneif 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 subsequentstate()queries see consistent input.See also
retro_input_poll_tThe C function pointer type whose signature this method implements.
- Return type:
- state(port, device, index, id)[source]¶
Return the current state of a single input control.
- Parameters:
- Return type:
- Returns:
The control’s current state, encoded per libretro’s input conventions.
See also
retro_input_state_tThe 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_DESCRIPTORSto 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_descriptorThe 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_INFOto 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_descriptionThe 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_CALLBACKto receive key-down/key-up events.Noneif 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_callbackThe C struct registered by the core that contains this callback.
- class Direction[source]¶
Bases:
EnumCardinal direction used to match against directional buttons across device types.
- RIGHT = 1¶
- UP = 2¶
- LEFT = 3¶
- DOWN = 4¶
- matches_direction(other)[source]¶
Return
Trueif the given device input matches this direction.- Return type:
- 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:
objectAggregation 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)¶