simvx.core.input.layouts

The backend mapping: which raw index on a device each named control is.

A device reports its buttons and axes by index, which is the only thing the engine truly knows about hardware it has never seen. A :class:DeviceLayout is the backend’s table for one kind of device (SDL’s controller database, the browser’s standard mapping, GLFW’s mouse numbering, the engine’s own pen table), and it is what lets an event carry Pen.BARREL_1 rather than “button 2”.

It is internal. A game never writes to it: every change a game or a player makes to what a control means is a rebind of an entry in the input map (InputMap.rebind(Controller.A, Controller.button(1))), which is per tree and survives with the player’s other rebinds.

Module Contents

Classes

DeviceLayout

The names one device gives its indices, and what it prints on each.

Functions

type_layout

The table for device_type: the backend’s own where it gave one, else the engine’s default.

default_raw

The raw control the engine entry control resolves to by default, unit-free.

raw_button

The raw control a backend’s button index is: the engine’s own numbering for what it is.

raw_axis

The raw control a backend’s axis index is, as :func:raw_button is for a button.

Data

API

simvx.core.input.layouts.__all__

[‘DeviceLayout’]

class simvx.core.input.layouts.DeviceLayout[source]

The names one device gives its indices, and what it prints on each.

Keyed by the controls themselves, so a misspelt name is an AttributeError where it is written::

DeviceLayout(DeviceType.PEN, buttons={Pen.TIP: 0, Pen.BARREL_1: 2, Pen.BARREL_2: 1},
             labels={Pen.BARREL_1: "Lower barrel"})

Each index has at most one name. A label is keyed by name, so it moves with the name when an override moves it.

device: simvx.core.input.controls.DeviceType

None

buttons: collections.abc.Mapping[Any, int]

‘field(…)’

axes: collections.abc.Mapping[Any, int]

‘field(…)’

labels: collections.abc.Mapping[Any, str]

‘field(…)’

__post_init__() → None[source]
__eq__(other: object) → bool[source]
__hash__

None

moved(buttons: collections.abc.Mapping[str, int] | None = None, axes: collections.abc.Mapping[str, int] | None = None) → simvx.core.input.layouts.DeviceLayout[source]

This layout with the given names moved to the given indices.

A name already at a target index that is not itself moved loses its index, because an index has one name. :meth:DeviceLayouts.override refuses that case with the fix; this is what applies a layer that was checked against a different base.

button_control(index: int) → simvx.core.input.controls.DeviceButton[source]

The control a press of index is: its name where the layout has one, else X.button(index).

axis_control(index: int) → simvx.core.input.controls.DeviceAxis[source]

The control motion of index is: its name where the layout has one, else X.axis(index).

button_index(button: simvx.core.input.controls.DeviceButton) → int | None[source]

The index button is on this layout, or None where it names nothing here.

A role resolves to this device type’s member of it: Pointer.PRIMARY is the mouse’s left on a mouse layout.

axis_index(axis: simvx.core.input.controls.DeviceAxis) → int | None[source]

The index axis is on this layout, whichever half or form it names, or None.

property primary: int | None[source]

The index of this device type’s member of Pointer.PRIMARY, which is what contact means.

button_label(index: int) → str[source]

What to print for button index: its name’s label, else its number.

axis_label(index: int) → str[source]

What to print for axis index: its name’s label, else its number.

simvx.core.input.layouts.KEYBOARD_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.MOUSE_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.DOM_MOUSE_LAYOUT

‘moved(…)’

simvx.core.input.layouts.TOUCH_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.PEN_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.W3C_PEN_LAYOUT

‘moved(…)’

simvx.core.input.layouts.TABLET_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.CONTROLLER_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.UNRECOGNISED_CONTROLLER_LAYOUT

‘DeviceLayout(…)’

simvx.core.input.layouts.DEFAULT_LAYOUTS: dict[simvx.core.input.controls.DeviceType, simvx.core.input.layouts.DeviceLayout]

None

simvx.core.input.layouts.type_layout(device_type: simvx.core.input.controls.DeviceType, backend: collections.abc.Mapping[simvx.core.input.controls.DeviceType, simvx.core.input.layouts.DeviceLayout]) → simvx.core.input.layouts.DeviceLayout[source]

The table for device_type: the backend’s own where it gave one, else the engine’s default.

simvx.core.input.layouts.default_raw(control: simvx.core.input.controls.DeviceControl) → simvx.core.input.controls.DeviceControl | None[source]

The raw control the engine entry control resolves to by default, unit-free.

A raw control (an index form, or a key, which is raw by nature) is its own. A named one resolves through the engine’s own table for its device type, which is the numbering raw indices are given in on every backend. A role and a name the table does not place have none.

simvx.core.input.layouts.raw_button(layout: simvx.core.input.layouts.DeviceLayout, index: int) → simvx.core.input.controls.DeviceButton[source]

The raw control a backend’s button index is: the engine’s own numbering for what it is.

A backend that numbers a device its own way (the browser’s mouse, the W3C pen) is translated here, so Mouse.button(1) is the right button under every backend. An index the backend’s table does not name passes through.

simvx.core.input.layouts.raw_axis(layout: simvx.core.input.layouts.DeviceLayout, index: int) → simvx.core.input.controls.DeviceAxis[source]

The raw control a backend’s axis index is, as :func:raw_button is for a button.