Docs / Input binder

Glossary: InputBinder

The members of InputBinder, in alphabetical order.

Color legend plain property method

Holds a game’s actions and the inputs bound to them, and runs the bound actions for the inputs polled each frame.

A class, in the namespace BorrowedTorch.InputBinding. Registering an action returns a RegisteredActionHandle, which binds its inputs. The binder keeps one input on one action at most, and isn’t thread-safe: use it from the game’s thread. The actions page and the binding page show it in context, with code.

Names are colored by what they are: a property or a method; values and fields keep the plain color.

Properties

Actions →

IReadOnlyList<RegisteredActionHandle> · Read-only. The handle of every registered action, in the order they were registered: the order a settings menu lists them in. A live view: it follows registrations and unregistrations, and can’t be changed through a cast.

InputBindingsPerAction →

int · Read-only. The number of slots of every action, set by the constructor: how many inputs an action can have bound at once.

Methods

InputBinder() →

InputBinder(int inputBindingsPerAction = 2) · A binder with no actions, whose actions will have that many slots each. Throws ArgumentOutOfRangeException below 1.

Parameter Type Description
inputBindingsPerAction int The number of slots per action: the columns of a settings menu. Default: 2.

GetAction() →

GetAction(string actionName) · The RegisteredActionHandle of the action of that name, or null when there is none, the name null included.

Parameter Type Description
actionName string The action’s name, compared exactly.

RegisterAction() →

RegisterAction(BaseAction action) · Registers an action built ahead, such as a ButtonAction, with every slot empty, and returns its handle. Throws ArgumentNullException for null, and InvalidOperationException when an action of that name is registered, the same action object included.

Parameter Type Description
action BaseAction The action. Registering it again after it was unregistered wakes its old handles.

RegisterActionRange() →

RegisterActionRange(params BaseAction[] actions) · Registers the actions in order, as RegisterAction does, and returns their handles in the same order, as an IReadOnlyList<RegisteredActionHandle>. Stops at the first action that throws: those before it stay registered. Throws ArgumentNullException for a null array.

Parameter Type Description
actions BaseAction[] The actions, in the order to register them.

RegisterButtonAction() →

RegisterButtonAction(string name, Action<ButtonState, int> callback, string description = null, object representation = null) · Registers a ButtonAction with every slot empty, and returns its handle. Throws ArgumentNullException for a null name, ArgumentException for an empty one, and InvalidOperationException when an action of that name is registered.

Parameter Type Description
name string The action’s name, unique in the binder.
callback Action<ButtonState, int> Called with the ButtonState and the player number of each bound input passed to Update. May be null: the action then does nothing.
description string Text for the settings menu. Default: null.
representation object Anything the game shows the action with. Default: null.

RegisterOneAxisAction() →

RegisterOneAxisAction(string name, Action<float, int> callback, string description = null, object representation = null) · Registers a OneAxisAction with every slot empty, and returns its handle. Throws as RegisterButtonAction does.

Parameter Type Description
name string The action’s name, unique in the binder.
callback Action<float, int> Called with the value and the player number of each bound input passed to Update. May be null.
description string Text for the settings menu. Default: null.
representation object Anything the game shows the action with. Default: null.

RegisterTwoAxesAction() →

RegisterTwoAxesAction(string name, Action<Vector2, int> callback, string description = null, object representation = null) · Registers a TwoAxesAction with every slot empty, and returns its handle. Throws as RegisterButtonAction does.

Parameter Type Description
name string The action’s name, unique in the binder.
callback Action<Vector2, int> Called with the value, a System.Numerics.Vector2, and the player number of each bound input passed to Update. May be null.
description string Text for the settings menu. Default: null.
representation object Anything the game shows the action with. Default: null.

UnregisterAction() →

UnregisterAction(string actionName) · Removes the action of that name and releases its inputs, which other actions can then be given. Returns false when there is no such action, the name null included. The action’s handles go inert.

Parameter Type Description
actionName string The action’s name.

UnregisterAction(RegisteredActionHandle actionHandle) · Removes the action the handle was issued for and releases its inputs. Returns false for null, or when that action isn’t registered: a stale handle never removes a later action registered under its name.

Parameter Type Description
actionHandle RegisteredActionHandle A handle of the action.

Update() →

Update(IReadOnlyList<ButtonInput> buttonInputs, IReadOnlyList<OneAxisInput> oneAxisInputs, IReadOnlyList<TwoAxesInput> twoAxesInputs, bool withShift, bool withCtrl, bool withAlt) · For each input of the three lists, in that order, finds the binding with the same identity and calls its action with the input’s state or value and PlayerNumber. An input bound to nothing is skipped, and every input passed calls its action, whatever its state. A key polled without a modifier goes to the binding of the held modifiers first, see the modifier keys page. The callbacks run inside the call. Allocates nothing.

Parameter Type Description
buttonInputs IReadOnlyList<ButtonInput> The buttons polled this frame, or null.
oneAxisInputs IReadOnlyList<OneAxisInput> The single axes polled this frame, or null.
twoAxesInputs IReadOnlyList<TwoAxesInput> The pairs of axes polled this frame, or null.
withShift bool Shift is held.
withCtrl bool Ctrl is held.
withAlt bool Alt is held.