Table of Contents

Class InputBindingService

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

The default input binding service. It reads the devices once a frame and works out the state of each action.

public sealed class InputBindingService : IInputBindingService, IDisposable
Inheritance
InputBindingService
Implements
Inherited Members

Constructors

InputBindingService(DeviceInputManager, InputContextManager)

Created by dependency injection. Makes itself the current InputBindingLocator when there is none.

public InputBindingService(DeviceInputManager deviceInputManager, InputContextManager contextManager)

Parameters

deviceInputManager DeviceInputManager
contextManager InputContextManager

Properties

KeysDown

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

public IReadOnlyList<Key> KeysDown { get; }

Property Value

IReadOnlyList<Key>

KeysPressed

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

public IReadOnlyList<Key> KeysPressed { get; }

Property Value

IReadOnlyList<Key>

Methods

Consume(string)

Marks the action consumed for the rest of this frame. Does nothing for an unregistered action.

public void Consume(string actionId)

Parameters

actionId string

ConsumeAll()

Marks every action consumed for the rest of this frame.

public void ConsumeAll()

Dispose()

Stops this service being the current InputBindingLocator.

public void Dispose()

GetAxisValue(string)

The axis value of the action this frame. Zero when it has been consumed or is not registered.

public float GetAxisValue(string actionId)

Parameters

actionId string

Returns

float

GetBinding(string)

Returns a copy of the action's current binding.

public InputBinding GetBinding(string actionId)

Parameters

actionId string

Returns

InputBinding

Exceptions

KeyNotFoundException

The action is not registered.

GetRegisteredActions()

The definitions of every registered action.

public IEnumerable<InputActionDefinition> GetRegisteredActions()

Returns

IEnumerable<InputActionDefinition>

HasAction(string)

Whether an action with this id is registered.

public bool HasAction(string id)

Parameters

id string

Returns

bool

IsPressed(string)

Whether the action is down this frame and has not been consumed. False for an unregistered action.

public 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.

public void RegisterAction(InputActionDefinition definition)

Parameters

definition InputActionDefinition

ResetBinding(string)

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

public void ResetBinding(string actionId)

Parameters

actionId string

SetBinding(string, InputBinding)

Replaces the action's binding with a copy of binding. The binding is kept when the action is re-registered.

public void SetBinding(string actionId, InputBinding binding)

Parameters

actionId string
binding InputBinding

Exceptions

ArgumentException

The binding's inputs do not match the action's type.

KeyNotFoundException

The action is not registered.

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.

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

Parameters

actionId string
axis GamepadAxis
invert bool
deadzone float

Exceptions

InvalidOperationException

The action is not an axis action.

SetGamepadBinding(string, params GamepadButton[])

Replaces the gamepad buttons of a button action with buttons.

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

Parameters

actionId string
buttons GamepadButton[]

Exceptions

InvalidOperationException

The action is not a button action.

SetGamepadButtonAxisBinding(string, GamepadButton, GamepadButton, float)

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

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

Parameters

actionId string
negative GamepadButton
positive GamepadButton
scale float

Exceptions

InvalidOperationException

The action is not an axis action.

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.

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

Parameters

actionId string
negative Key
positive Key
scale float

Exceptions

InvalidOperationException

The action is not an axis action.

SetKeyboardBinding(string, params Key[])

Replaces the keyboard keys of a button action with keys.

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

Parameters

actionId string
keys Key[]

Exceptions

InvalidOperationException

The action is not a button action.

TryGetBinding(string, out InputBinding)

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

public bool TryGetBinding(string actionId, out InputBinding binding)

Parameters

actionId string
binding InputBinding

Returns

bool

UnregisterAction(string)

Removes an action. An unknown id does nothing.

public void UnregisterAction(string actionId)

Parameters

actionId string

Update(float)

Works out this frame's state from the devices. Does nothing once the frame loop drives the service, so calling it as well is harmless.

public void Update(float deltaTime)

Parameters

deltaTime float

WasJustPressed(string)

Whether the action went down this frame and has not been consumed. False for an unregistered action.

public bool WasJustPressed(string actionId)

Parameters

actionId string

Returns

bool

WasJustPressedOrRepeated(string)

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

public 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. False for an unregistered action.

public bool WasJustReleased(string actionId)

Parameters

actionId string

Returns

bool