Open-Source Wikis

/

Bevy

/

Packages

/

bevy_input

bevyengine/bevy

bevy_input

Keyboard, mouse, touch, and gamepad input. Defines the events, resources, and per-frame state types other crates write into. Backend-agnostic — bevy_winit and bevy_gilrs populate the events.

Purpose

The crate defines:

  • Per-frame button state via ButtonInput<T> (ButtonInput<KeyCode>, ButtonInput<MouseButton>, ButtonInput<GamepadButton>).
  • Axis state via Axis<T> (Axis<GamepadAxis>, Axis<MouseScrollAxis>).
  • Events for raw input (KeyboardInput, MouseButtonInput, MouseMotion, MouseWheel, TouchInput, GamepadButtonChangedEvent, GamepadAxisChangedEvent, GamepadConnectionEvent).
  • Components for connected gamepad entities.
  • System sets in PreUpdate so other crates can place themselves before/after input gathering.

Directory layout

crates/bevy_input/src/
├── lib.rs           # InputPlugin
├── button_input.rs  # ButtonInput<T>
├── axis.rs          # Axis<T>
├── keyboard.rs      # KeyboardInput, KeyCode, NativeKey, NativeKeyCode
├── mouse.rs         # MouseButtonInput, MouseMotion, MouseWheel
├── touch.rs         # TouchInput, TouchPhase
├── gamepad.rs       # Gamepad component, GamepadButton, GamepadAxis, etc.
├── gestures.rs      # PinchGesture, RotationGesture, DoubleTap
└── prelude.rs

Key abstractions

Type File Description
ButtonInput<T> crates/bevy_input/src/button_input.rs pressed, just_pressed, just_released queries.
Axis<T> crates/bevy_input/src/axis.rs get(input) returns the current axis value.
KeyCode crates/bevy_input/src/keyboard.rs Position-independent key codes (matches winit).
MouseButton, MouseMotion, MouseWheel crates/bevy_input/src/mouse.rs Mouse types.
TouchInput, Touches crates/bevy_input/src/touch.rs Touch input state and events.
Gamepad, GamepadButton, GamepadAxis crates/bevy_input/src/gamepad.rs Gamepad entity components and types.

How it works

  1. Backend (bevy_winit, bevy_gilrs) sends events.
  2. update_input systems in PreUpdate move just_pressed/just_released flags from the previous frame.
  3. User systems read ButtonInput and Axis resources, or read events directly with EventReader<KeyboardInput>.

A Gamepad is an entity, not a resource, so multiple controllers are first-class. Per-pad state (button input, axes) lives in components on that entity.

Integration points

  • Depends on: bevy_app, bevy_ecs, bevy_math, bevy_reflect.
  • Depended on by: bevy_winit, bevy_gilrs, bevy_picking, bevy_input_focus, bevy_ui, bevy_ui_widgets, …

Entry points for modification

  • New input device kind: define types here; populate from a backend crate.
  • New key code: keep the KeyCode enum aligned with winit's KeyCode.
  • New gesture: gestures.rs.

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

bevy_input – Bevy wiki | Factory