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.
public sealed class InputSystem : IStateHashedInheritance
Implements
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.
public InputSystem(InputMap first)Parameters
first InputMap
Properties
Devices
The devices and their state.
public InputDevices Devices { get; }Property Value
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).
public IReadOnlyList<InputEvent> Events { get; }Property Value
KeyLabels
The labels of the player’s keyboard layout, when the backend knows them.
public IKeyLabels? KeyLabels { get; }Property Value
Layers
The input layers events pass through before gameplay.
public InputLayers Layers { get; }Property Value
Players
The local players; player 1 owns every device until devices are paired.
public Players Players { get; }Property Value
PolledSources
The polled sources read as devices (a host’s extra input, a test’s hand-set input).
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.
public IReadOnlyList<RoutedEvent> Routed { get; }Property Value
Text
The text channel.
public TextInput Text { get; }Property Value
Trace
Whether Routed records where each event of the frame went. Off by default; the game’s diagnostics turn it on while they measure.
public bool Trace { get; set; }Property Value
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.
public DeviceId AddPolled(IInputSource source)Parameters
source IInputSource
Returns
BeginFrame()
Starts a frame: routes the backend’s events, then the sent ones. Called by the loop once per frame.
public void BeginFrame()Connect(IInputBackend?, IKeyLabels?, IGamepadRumble?, ITextInputControl?)
Connects the platform’s input: its event backend and the optional features it offers.
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.
public void EndUpdate()HashState(StateHasher)
Adds the players beyond player 1 and the pairings (HashState); player 1’s map is hashed by its owner.
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.
public IDisposable ListenForPress(Action<InputEvent> pressed)Parameters
pressed Action<InputEvent>
Returns
ReleaseAll()
Releases every key, button and pointer and forgets which layer took what (focus lost, suspended).
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.
public void Route(in InputEvent e)Parameters
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.
public bool Rumble(PlayerInput player, float low, float high, double seconds)Parameters
player PlayerInput
low float
high float
seconds double
Returns
Rumble(DeviceId, float, float, double)
Rumbles one gamepad (see Rumble).
public bool Rumble(DeviceId pad, float low, float high, double seconds)Parameters
pad DeviceId
low float
high float
seconds double
Returns
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.
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.
public void Send(in InputEvent e)Parameters
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.
public IInputSource ViewOf(PlayerInput player)Parameters
player PlayerInput