Interface IInputBindingService
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
KeysPressed
Every key held down this step. Named as on IKeyboardManager.
IReadOnlyList<Key> KeysPressed { get; }
Property Value
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
actionIdstring
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
actionIdstring
Returns
GetBinding(string)
Returns a copy of the action's current binding. Throws KeyNotFoundException when the action is not registered.
InputBinding GetBinding(string actionId)
Parameters
actionIdstring
Returns
GetRegisteredActions()
The definitions of every registered action.
IEnumerable<InputActionDefinition> GetRegisteredActions()
Returns
HasAction(string)
Whether an action with this id is registered.
bool HasAction(string id)
Parameters
idstring
Returns
IsPressed(string)
Whether the action is down this frame and has not been consumed.
bool IsPressed(string actionId)
Parameters
actionIdstring
Returns
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
definitionInputActionDefinition
ResetBinding(string)
Returns the action to its default binding, discarding the player's changes.
void ResetBinding(string actionId)
Parameters
actionIdstring
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
actionIdstringbindingInputBinding
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
actionIdstringaxisGamepadAxisinvertbooldeadzonefloat
SetGamepadBinding(string, params GamepadButton[])
Replaces the gamepad buttons of a button action with buttons.
void SetGamepadBinding(string actionId, params GamepadButton[] buttons)
Parameters
actionIdstringbuttonsGamepadButton[]
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
actionIdstringnegativeGamepadButtonpositiveGamepadButtonscalefloat
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
SetKeyboardBinding(string, params Key[])
Replaces the keyboard keys of a button action with keys.
void SetKeyboardBinding(string actionId, params Key[] keys)
Parameters
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
actionIdstringbindingInputBinding
Returns
UnregisterAction(string)
Removes an action. An unknown id does nothing.
void UnregisterAction(string actionId)
Parameters
actionIdstring
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
deltaTimefloat
WasJustPressed(string)
Whether the action went down this frame and has not been consumed.
bool WasJustPressed(string actionId)
Parameters
actionIdstring
Returns
WasJustPressedOrRepeated(string)
WasJustPressed(string), plus every OS key repeat while the action is held.
bool WasJustPressedOrRepeated(string actionId)
Parameters
actionIdstring
Returns
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
actionIdstring