leafwing_input_manager

Module user_input

source
Expand description

Helpful abstractions over user inputs of all sorts.

This module simplifies user input handling in Bevy applications by providing abstractions and utilities for various input devices like gamepads, keyboards, and mice. It offers a unified interface for querying input values and states, reducing boilerplate code and making user interactions easier to manage.

The foundation of this module lies in the UserInput trait, used to define the behavior expected from a specific user input source.

Need something specific? You can also create your own inputs by implementing the trait for specific needs.

Feel free to suggest additions to the built-in inputs if you have a common use case!

§Control Types

UserInputs use the method UserInput::kind returning an InputControlKind to classify the behavior of the input (buttons, analog axes, etc.).

  • InputControlKind::Button: Represents a digital input with an on/off state (e.g., button press). These inputs typically provide two values, typically 0.0 (inactive) and 1.0 (fully active).

  • InputControlKind::Axis: Represents an analog input (e.g., mouse wheel) with a continuous value typically ranging from -1.0 (fully left/down) to 1.0 (fully right/up). Non-zero values are considered active.

  • InputControlKind::DualAxis: Represents a combination of two analog axes (e.g., thumb stick). These inputs provide separate X and Y values typically ranging from -1.0 to 1.0. Non-zero values are considered active.

§Basic Inputs

UserInputs use the method UserInput::decompose returning a BasicInputs used for clashing detection, see clashing input check for details.

§Built-in Inputs

§Gamepad Inputs

§Keyboard Inputs

  • Check physical keys presses using Bevy’s KeyCode directly.
  • Use ModifierKey to check for either left or right modifier keys is pressed.

§Mouse Inputs

§Complex Composition

Re-exports§

Modules§

Enums§

Traits§

  • A trait used for axis-like user inputs, which provide a continuous value.
  • A trait used for buttonlike user inputs, which can be pressed or released.
  • A trait used for dual-axis-like user inputs, which provide separate X and Y values.
  • A trait for registering inputs.
  • A trait used for triple-axis-like user inputs, which provide separate X, Y, and Z values.
  • A trait for defining the behavior expected from different user input sources.