一键导入
bevy-input
Reference for handling input in Bevy — keyboard, mouse, touch, gamepad, events vs resources, physical vs logical keys, and enhanced input.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Reference for handling input in Bevy — keyboard, mouse, touch, gamepad, events vs resources, physical vs logical keys, and enhanced input.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Reference for Avian physics engine — rigid bodies, colliders, joints, spatial queries, collision events, character controllers, and debug rendering.
Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading.
Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings.
Reference for Bevy Scene Notation (BSN) — the bsn! macro for defining inline scenes with components, children, relationships, observers, and dynamic props.
Reference for cameras in Bevy — Camera2d, Camera3d, viewports, projection, render layers, mouse-to-world, and free camera controllers.
Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing.
| name | bevy-input |
| description | Reference for handling input in Bevy — keyboard, mouse, touch, gamepad, events vs resources, physical vs logical keys, and enhanced input. |
| metadata | {"crate":"bevy_input","bevy":"0.19"} |
MessageReader<T> for reacting to any input of a typeButtonInput<T>, Axis<T>, Touches, Gamepads for specific state queries| Resource | Purpose |
|---|---|
ButtonInput<KeyCode> | Keyboard keys |
ButtonInput<MouseButton> | Mouse buttons |
Axis<GamepadAxis> | Gamepad analog sticks/triggers |
ButtonInput<GamepadButton> | Gamepad buttons |
Touches | Touch state |
Gamepads | Connected gamepads |
| Method | Returns true |
|---|---|
pressed(k) | Between press and release |
just_pressed(k) | One frame after press |
just_released(k) | One frame after release |
any_pressed([k1, k2]) | Any in list pressed |
fn jump(input: Res<ButtonInput<KeyCode>>) {
if input.just_pressed(KeyCode::Space) { /* jump */ }
}
key_code — physical position on keyboard (use for gameplay)logical_key — mapped to OS layout (use for text)fn shoot(mouse: Res<ButtonInput<MouseButton>>) {
if mouse.just_pressed(MouseButton::Left) { }
}
Mouse motion, cursor, wheel, gestures — read via EventReader:
fn mouse_events(
mut motion: MessageReader<MouseMotion>,
mut cursor: MessageReader<CursorMoved>,
mut wheel: MessageReader<MouseWheel>,
) {
for ev in motion.read() { }
for ev in cursor.read() { }
for ev in wheel.read() { }
}
fn touch(touches: Res<Touches>) {
for touch in touches.iter_just_pressed() { }
for touch in touches.iter_just_released() { }
for touch in touches.iter() { }
}
fn gamepad(gamepads: Query<&Gamepad>, buttons: Res<ButtonInput<GamepadButton>>) {
for pad in &gamepads {
if buttons.just_pressed(GamepadButton::South) { }
}
}
commands.queue(GamepadRumbleRequest::Add {
gamepad: entity,
intensity: GamepadRumbleIntensity::strong_motor(0.5),
duration: Duration::from_millis(300),
});
let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
if ctrl && shift && input.just_pressed(KeyCode::KeyA) { }
Use observers to avoid scheduling issues with FixedUpdate:
fn apply_movement(trigger: On<Fire<Move>>, mut players: Query<&mut Transform>) {
let mut t = players.get_mut(trigger.context).unwrap();
t.translation += trigger.value.extend(0.0);
}