Table of Contents

Interface IInputBindingService

Namespace
BSGameLib.Game.Input
Assembly
BSGameLib.Game.dll

Binds game actions to keys, gamepad buttons and axes, so that game code reads actions rather than devices and the player can change the bindings.

public interface IInputBindingService

Properties

KeysDown

The keys that went down this step. Named as on IKeyboardManager.

IReadOnlyList<Key> KeysDown { get; }

Property Value

IReadOnlyList<Key>

KeysPressed

Every key held down this step. Named as on IKeyboardManager.

IReadOnlyList<Key> KeysPressed { get; }

Property Value

IReadOnlyList<Key>

Methods

Consume(string)

Marks the action consumed for the rest of this frame, so that no other code sees it as pressed.

void Consume(string actionId)

Parameters

actionId string

ConsumeAll()

Marks every action consumed for the rest of this frame.

void ConsumeAll()

GetAxisValue(string)

The axis value of the action this frame, from -1 to 1. Zero when it has been consumed.

float GetAxisValue(string actionId)

Parameters

actionId string

Returns

float

GetBinding(string)

Returns a copy of the action's current binding. Throws KeyNotFoundException when the action is not registered.

InputBinding GetBinding(string actionId)

Parameters

actionId string

Returns

InputBinding

GetRegisteredActions()

The definitions of every registered action.

IEnumerable<InputActionDefinition> GetRegisteredActions()

Returns

IEnumerable<InputActionDefinition>

HasAction(string)

Whether an action with this id is registered.

bool HasAction(string id)

Parameters

id string

Returns

bool

IsPressed(string)

Whether the action is down this frame and has not been consumed.

bool IsPressed(string actionId)

Parameters

actionId string

Returns

bool

RegisterAction(InputActionDefinition)

Registers an action, or updates the definition of an action with the same id. A binding the player set is kept.

void RegisterAction(InputActionDefinition definition)

Parameters

definition InputActionDefinition

ResetBinding(string)

Returns the action to its default binding, discarding the player's changes.

void ResetBinding(string actionId)

Parameters

actionId string

SetBinding(string, InputBinding)

Replaces the action's binding with a copy of binding. The binding must match the action's type.

void SetBinding(string actionId, InputBinding binding)

Parameters

actionId string
binding InputBinding

SetGamepadAxisBinding(string, GamepadAxis, bool, float)

Sets the gamepad stick or trigger of an axis action. The value can be inverted and is read as 0 inside the deadzone.

void SetGamepadAxisBinding(string actionId, GamepadAxis axis, bool invert = false, float deadzone = 0.2)

Parameters

actionId string
axis GamepadAxis
invert bool
deadzone float

SetGamepadBinding(string, params GamepadButton[])

Replaces the gamepad buttons of a button action with buttons.

void SetGamepadBinding(string actionId, params GamepadButton[] buttons)

Parameters

actionId string
buttons GamepadButton[]

SetGamepadButtonAxisBinding(string, GamepadButton, GamepadButton, float)

Sets the gamepad buttons of an axis action to one pair. Each held button adds scale to the value.

void SetGamepadButtonAxisBinding(string actionId, GamepadButton negative, GamepadButton positive, float scale = 1)

Parameters

actionId string
negative GamepadButton
positive GamepadButton
scale float

SetKeyboardAxisBinding(string, Key, Key, float)

Sets the keyboard keys of an axis action to one key pair. Each held key adds scale to the value.

void SetKeyboardAxisBinding(string actionId, Key negative, Key positive, float scale = 1)

Parameters

actionId string
negative Key
positive Key
scale float

SetKeyboardBinding(string, params Key[])

Replaces the keyboard keys of a button action with keys.

void SetKeyboardBinding(string actionId, params Key[] keys)

Parameters

actionId string
keys Key[]

TryGetBinding(string, out InputBinding)

Returns a copy of the action's current binding, and whether the action is registered.

bool TryGetBinding(string actionId, out InputBinding binding)

Parameters

actionId string
binding InputBinding

Returns

bool

UnregisterAction(string)

Removes an action. An unknown id does nothing.

void UnregisterAction(string actionId)

Parameters

actionId string

Update(float)

Reads the devices and works out this frame's state for every action. A game's frame loop does this once a frame; calling it as well changes nothing.

void Update(float deltaTime)

Parameters

deltaTime float

WasJustPressed(string)

Whether the action went down this frame and has not been consumed.

bool WasJustPressed(string actionId)

Parameters

actionId string

Returns

bool

WasJustPressedOrRepeated(string)

WasJustPressed(string), plus every OS key repeat while the action is held.

bool WasJustPressedOrRepeated(string actionId)

Parameters

actionId string

Returns

bool

Remarks

For actions where holding the key should keep acting: deleting a character, stepping through a list. Most actions want the plain WasJustPressed(string) -- firing, opening a menu, toggling anything -- which is why this is a separate call rather than a change to what "just pressed" means for everybody. Movement in particular must not use it: movement is read as a level and paced by the game, not by the OS repeat rate.

Keyboard only. A held gamepad button produces no repeat events, so for an action bound to one this reports exactly what WasJustPressed(string) does.

WasJustReleased(string)

Whether the action went up this frame and has not been consumed.

bool WasJustReleased(string actionId)

Parameters

actionId string

Returns

bool