bevy/crates/bevy_input/src/system.rs

23 lines
688 B
Rust
Raw Normal View History

2020-06-15 19:47:35 +00:00
use crate::keyboard::{ElementState, KeyCode, KeyboardInput};
2020-06-04 06:53:00 +00:00
use bevy_app::{AppExit, EventReader, Events};
2020-07-10 04:18:35 +00:00
use bevy_ecs::{Local, Res, ResMut};
2020-04-19 19:13:04 +00:00
2020-07-10 04:18:35 +00:00
#[derive(Default)]
pub struct ExitOnEscapeState {
reader: EventReader<KeyboardInput>,
}
pub fn exit_on_esc_system(
mut state: Local<ExitOnEscapeState>,
keyboard_input_events: Res<Events<KeyboardInput>>,
mut app_exit_events: ResMut<Events<AppExit>>,
) {
for event in state.reader.iter(&keyboard_input_events) {
if let Some(key_code) = event.key_code {
if event.state == ElementState::Pressed && key_code == KeyCode::Escape {
app_exit_events.send(AppExit);
2020-04-30 23:29:52 +00:00
}
}
2020-07-10 04:18:35 +00:00
}
2020-04-25 01:55:15 +00:00
}