BerylliumInputBinder 1.2.3
dotnet add package BerylliumInputBinder --version 1.2.3
NuGet\Install-Package BerylliumInputBinder -Version 1.2.3
<PackageReference Include="BerylliumInputBinder" Version="1.2.3" />
<PackageVersion Include="BerylliumInputBinder" Version="1.2.3" />
<PackageReference Include="BerylliumInputBinder" />
paket add BerylliumInputBinder --version 1.2.3
#r "nuget: BerylliumInputBinder, 1.2.3"
#:package BerylliumInputBinder@1.2.3
#addin nuget:?package=BerylliumInputBinder&version=1.2.3
#tool nuget:?package=BerylliumInputBinder&version=1.2.3
Beryllium Input Binder
Class library for managing various types of input binding to game actions.
Actions come in three shapes — button, one-axis and two-axes — and each action can hold several input bindings (2 by default). Registration and binding are separate on purpose: a game first registers its actions (by name/description), then the player binds inputs to them later in a settings menu.
Quick start
var binder = new InputBinder(inputBindingsPerAction: 2);
// 1. Register actions once at startup. Each call returns a handle you can keep or look up later.
var jump = binder.RegisterButton("Jump", (state, player) => Player.Jump(),
description: "Jump over obstacles")
.WithDefaultBinding(0, Input.Key(32)) // keyboard Space
.WithDefaultBinding(1, Input.GamePadButton(0)); // gamepad A
var look = binder.RegisterTwoAxes("Look", (delta, player) => Camera.Rotate(delta))
.WithDefaultBinding(0, Input.MouseAxes(0));
// Batch-register pre-built actions if you prefer defining them elsewhere:
binder.RegisterRange(
new OneAxisAction("Throttle", (v, p) => Ship.SetThrottle(v)),
new ButtonAction("Fire", (s, p) => Ship.Fire()));
// 2. Drive the binder each frame with the inputs you polled.
// Update takes IReadOnlyList (arrays or List<T>) and is O(1) per input with zero allocations,
// so it is safe to call every frame. Any list may be null.
binder.Update(buttonInputs, oneAxisInputs, twoAxesInputs,
withShift: shiftHeld, withCtrl: ctrlHeld, withAlt: altHeld);
Rebinding menu
Enumerate binder.Actions (or binder.GetAction(name)) to build a settings screen, then bind
through the handle. Bind reports a conflict instead of silently stealing the input:
foreach (var action in binder.Actions)
Console.WriteLine($"{action.Name} ({action.Type}): {action.Description}");
var result = jump.Bind(0, Input.Key(newKeyCode));
if (result.Result == InputBinderResults.InputBoundToOtherAction)
{
// The input is already bound to result.ConflictingAction — ask the player, then override:
jump.Bind(0, Input.Key(newKeyCode), forceMap: true);
}
jump.Unbind(1); // clear a slot
Each handle exposes Name, Description, Type, Representation and its current Inputs
(one slot per binding; a slot is null when unbound), so you can render the current mapping.
Input factories
Input provides terse factories for binding:
| Kind | Factories |
|---|---|
| Button | Input.Key(code, modifier?), Input.MouseButton(n), Input.GamePadButton(n), Input.MidiButton(n) |
| One axis | Input.MouseAxis(id), Input.GamePadAxis(id), Input.MidiAxis(id), Input.Axis(source, id) |
| Two axes | Input.MouseAxes(id), Input.GamePadAxes(id), Input.Axes(source, id) |
Keyboard button bindings may carry a ButtonModifiers value (Shift/Ctrl/Alt); the Update
flags tell the binder which modifiers are currently held so the right binding fires.
When polling inputs for Update, construct them directly so you can set the live state:
new ButtonInput(InputSources.Keyboard, 32) { State = ButtonStates.Pressed, PlayerNumber = 0 }
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.