docs/bevy/examples/input/keyboard_modifiers.rs 607 B · 20 lines · raw · history

1 //! Demonstrates using key modifiers (ctrl, shift).
2
3 use bevy::prelude::*;
4
5 fn main() {
6 App::new()
7 .add_plugins(DefaultPlugins)
8 .add_systems(Update, keyboard_input_system)
9 .run();
10 }
11
12 /// This system prints when `Ctrl + Shift + A` is pressed
13 fn keyboard_input_system(input: Res<ButtonInput<KeyCode>>) {
14 let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
15 let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
16
17 if ctrl && shift && input.just_pressed(KeyCode::KeyA) {
18 info!("Just pressed Ctrl + Shift + A!");
19 }
20 }