libretro.drivers.input.driver

Protocol definition for input drivers.

See also

libretro.api.input

The matching ctypes types, device identifiers, and callback definitions.

Classes

InputDriver

Protocol for drivers that provide input device state to a core.

class InputDriver[source]

Bases: Protocol

Protocol for drivers that provide input device state to a core.

See also

libretro.api.input

The matching ctypes types, device identifiers, and callback definitions.

abstractmethod 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

abstractmethod 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 (InputDevice) – The input device class registered to port.

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

  • _id (int) – 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.

abstract 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.

abstract 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.

keyboard_event(down, keycode, character, modifiers)[source]

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

abstract 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.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
abstract 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.

abstract 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.

abstract 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.