OverviewThis WebsiteHome LabTrading BotEcosimProcedural Generation
Projects

Keybind Plugin

A Bevy plugin that maps physical inputs — keyboard keys, mouse buttons, gamepad axes, touch — to named actions. Game code listens to actions, not hardware; rebinding is a runtime change with no game logic involved.


Design

Action-Based Binding

Inputs are stored in a KeyBindings resource as a map from action name to a list of InputType values. One action can be triggered by multiple inputs simultaneously — "zoom_in" could be bound to both scroll wheel up and the + key without any special-casing. The plugin reads all registered bindings each frame and emits a MessageEvent for any action whose input is active.


Coverage

Input Types

The InputType enum covers every major input source Bevy exposes:

  1. Keyboard — any KeyCode
  2. MouseButton — left, right, middle, or extra buttons
  3. MouseWheel — up/down scroll delta
  4. MouseMotion — raw cursor delta for look/orbit
  5. GamepadButton — any button on any connected gamepad
  6. GamepadAxis — analogue stick or trigger with deadzone
  7. TouchInput — touch phase detection

State Tracking

Pressed / JustPressed / Released

Each action emits an ActionState alongside the action name: JustPressed fires once on the first frame the input is active, Pressed fires every frame it remains held, and JustReleased fires once when the input is lifted. This mirrors Bevy's own input API so game systems can use familiar patterns without querying raw hardware.


Integration

Orbit Camera

The keybind plugin is the default input provider for the Orbit Camera plugin. KeybindOrbitInput implements OrbitCameraInput by reading MessageEvents and translating them into camera deltas. Rebinding the camera controls at runtime requires only updating the KeyBindings resource — neither the camera plugin nor the game loop need to know.