bevy/examples/input/keyboard_modifiers.rs
Guim Caballero c3a72e9dc8 Add keyboard modifier example (#1656) (#1657)
This PR adds a small example that shows how to use Keyboard modifiers, as shown in [this](https://github.com/bevyengine/bevy/issues/1654#issuecomment-798966921) snippet.

Fixes #1656.

Co-authored-by: guimcaballero <guim.caballero@gmail.com>
2021-03-14 21:00:36 +00:00

21 lines
604 B
Rust

use bevy::{
input::{keyboard::KeyCode, Input},
prelude::*,
};
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_system(keyboard_input_system.system())
.run();
}
/// This system prints when Ctrl + Shift + A is pressed
fn keyboard_input_system(input: Res<Input<KeyCode>>) {
let shift = input.pressed(KeyCode::LShift) || input.pressed(KeyCode::RShift);
let ctrl = input.pressed(KeyCode::LControl) || input.pressed(KeyCode::RControl);
if ctrl && shift && input.just_pressed(KeyCode::A) {
println!("Just pressed Ctrl + Shift + A!");
}
}