bevy/examples/input/keyboard_input.rs

26 lines
583 B
Rust
Raw Normal View History

//! Demonstrates handling a key press/release.
use bevy::prelude::*;
2020-04-04 21:59:49 +00:00
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, keyboard_input_system)
2020-04-04 21:59:49 +00:00
.run();
}
2020-06-05 06:55:12 +00:00
/// This system prints 'A' key state
fn keyboard_input_system(keyboard_input: Res<Input<KeyCode>>) {
if keyboard_input.pressed(KeyCode::A) {
info!("'A' currently pressed");
}
2020-06-05 06:55:12 +00:00
if keyboard_input.just_pressed(KeyCode::A) {
info!("'A' just pressed");
}
2020-04-04 21:59:49 +00:00
2020-06-05 06:55:12 +00:00
if keyboard_input.just_released(KeyCode::A) {
info!("'A' just released");
}
2020-04-04 21:59:49 +00:00
}