Skip to content

InputAPI reference

Class InputSystem

Namespace: MicroEngine.Input
Assembly: MicroEngine.Input.dll
Guide: Input

The engine’s input: the devices and their events, the routing through input layers, the players and their action maps, and the text channel. Each frame the events of the platform’s input backend (and those sent with Send) are routed through Layers; what no layer takes becomes the devices’ polled state and Events. Each update samples every player’s map from the devices they hear.

C#
public sealed class InputSystem : IStateHashed

Inheritance

object ← InputSystem

Implements

IStateHashed

Remarks

A game rarely needs this directly: Game.Input is player 1’s map and Game.Players the players. Read Events for what actions cannot express (a tap’s position, a gesture, the order of presses).

Constructors

InputSystem(InputMap)

Creates the input with player 1 reading first.

C#
public InputSystem(InputMap first)

Parameters

first InputMap

Properties

Devices

The devices and their state.

C#
public InputDevices Devices { get; }

Property Value

InputDevices

Events

The events no layer took, since the previous update, in order: read them in an update for what actions cannot say. Each event is seen by exactly one update (frames that run no update keep them for the next).

C#
public IReadOnlyList<InputEvent> Events { get; }

Property Value

IReadOnlyList<InputEvent>

KeyLabels

The labels of the player’s keyboard layout, when the backend knows them.

C#
public IKeyLabels? KeyLabels { get; }

Property Value

IKeyLabels?

Layers

The input layers events pass through before gameplay.

C#
public InputLayers Layers { get; }

Property Value

InputLayers

Players

The local players; player 1 owns every device until devices are paired.

C#
public Players Players { get; }

Property Value

Players

PolledSources

The polled sources read as devices (a host’s extra input, a test’s hand-set input).

C#
public IReadOnlyList<(DeviceId Id, IInputSource Source)> PolledSources { get; }

Property Value

IReadOnlyList<(DeviceId Id, IInputSource Source)>

Routed

While Trace is on, the events routed this frame (device changes excepted) in order, each with the layer that took it, or none when it reached the devices and gameplay: the answer to “why did my action not fire?” when a menu, the on-screen controls or another layer took the press.

C#
public IReadOnlyList<RoutedEvent> Routed { get; }

Property Value

IReadOnlyList<RoutedEvent>

Text

The text channel.

C#
public TextInput Text { get; }

Property Value

TextInput

Trace

Whether Routed records where each event of the frame went. Off by default; the game’s diagnostics turn it on while they measure.

C#
public bool Trace { get; set; }

Property Value

bool

Methods

AddPolled(IInputSource)

Reads source as one more device, every update: its keys, gamepad and pointer, merged like one keyboard and one pad. Returns the id players pair it by.

C#
public DeviceId AddPolled(IInputSource source)

Parameters

source IInputSource

Returns

DeviceId

BeginFrame()

Starts a frame: routes the backend’s events, then the sent ones. Called by the loop once per frame.

C#
public void BeginFrame()

Connect(IInputBackend?, IKeyLabels?, IGamepadRumble?, ITextInputControl?)

Connects the platform’s input: its event backend and the optional features it offers.

C#
public void Connect(IInputBackend? backend, IKeyLabels? labels = null, IGamepadRumble? rumble = null, ITextInputControl? text = null)

Parameters

backend IInputBackend?

labels IKeyLabels?

rumble IGamepadRumble?

text ITextInputControl?

EndUpdate()

Ends an update: edge detection of every map, presses already released stop reading as held, the wheel and the update’s events are cleared. Called by the loop after each fixed update.

C#
public void EndUpdate()

HashState(StateHasher)

Adds the players beyond player 1 and the pairings (HashState); player 1’s map is hashed by its owner.

C#
public void HashState(StateHasher hash)

Parameters

hash StateHasher

ListenForPress(Action<InputEvent>)

Takes the next key or gamepad-button press of any device away from everything else and hands it to pressed, once: the “press a key for jump” step of a rebinding screen (BindFrom). Dispose the result to stop listening before a press came.

C#
public IDisposable ListenForPress(Action<InputEvent> pressed)

Parameters

pressed Action<InputEvent>

Returns

IDisposable

ReleaseAll()

Releases every key, button and pointer and forgets which layer took what (focus lost, suspended).

C#
public void ReleaseAll()

Route(in InputEvent)

Routes one event now: to the layer that took the press it belongs to, else through the layers from the top, else into the devices’ state and Events.

C#
public void Route(in InputEvent e)

Parameters

e InputEvent

Rumble(PlayerInput, float, float, double)

Rumbles every gamepad player hears: low-frequency (heavy) and high-frequency (light) motors at 0..1 for seconds. Returns false when none could rumble.

C#
public bool Rumble(PlayerInput player, float low, float high, double seconds)

Parameters

player PlayerInput

low float

high float

seconds double

Returns

bool

Rumble(DeviceId, float, float, double)

Rumbles one gamepad (see Rumble).

C#
public bool Rumble(DeviceId pad, float low, float high, double seconds)

Parameters

pad DeviceId

low float

high float

seconds double

Returns

bool

Sample()

Samples every player’s actions from the devices they hear and makes the pending events this update’s Events. Called by the loop before each fixed update.

C#
public void Sample()

Send(in InputEvent)

Queues an event as if a device had produced it; it is routed with the next frame’s events, after the backend’s. Scripted runs and tests drive input this way, through the same layers and state as real devices.

C#
public void Send(in InputEvent e)

Parameters

e InputEvent

ViewOf(PlayerInput)

What player hears, read as one polled source: the devices they own and the polled sources they own, a key or button down when any has it down.

C#
public IInputSource ViewOf(PlayerInput player)

Parameters

player PlayerInput

Returns

IInputSource