bevy/examples/input/keyboard_input.rs

27 lines
599 B
Rust
Raw Normal View History

2020-06-05 06:49:36 +00:00
use bevy::{
input::{keyboard::KeyCode, Input},
prelude::*,
};
2020-04-04 21:59:49 +00:00
fn main() {
App::build()
.add_plugin_group(DefaultPlugins)
2020-06-05 06:55:12 +00:00
.add_system(keyboard_input_system.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) {
println!("'A' currently pressed");
}
2020-06-05 06:55:12 +00:00
if keyboard_input.just_pressed(KeyCode::A) {
println!("'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) {
println!("'A' just released");
}
2020-04-04 21:59:49 +00:00
}