bevy/crates/bevy_input/src/system.rs

21 lines
847 B
Rust
Raw Normal View History

2020-04-25 01:55:15 +00:00
use crate::keyboard::{ElementState, KeyboardInput, VirtualKeyCode};
2020-06-04 06:53:00 +00:00
use bevy_app::{AppExit, EventReader, Events};
2020-04-19 19:13:04 +00:00
use legion::prelude::*;
2020-06-04 06:53:00 +00:00
pub fn exit_on_esc_system(_resources: &mut Resources) -> Box<dyn Schedulable> {
let mut keyboard_input_event_reader = EventReader::<KeyboardInput>::default();
2020-05-14 00:52:47 +00:00
(move |keyboard_input_events: Res<Events<KeyboardInput>>,
mut app_exit_events: ResMut<Events<AppExit>>| {
2020-04-30 23:29:52 +00:00
for event in keyboard_input_event_reader.iter(&keyboard_input_events) {
if let Some(virtual_key_code) = event.virtual_key_code {
if event.state == ElementState::Pressed
&& virtual_key_code == VirtualKeyCode::Escape
{
app_exit_events.send(AppExit);
2020-04-19 19:13:04 +00:00
}
2020-04-30 23:29:52 +00:00
}
}
})
.system_named("exit_on_esc")
2020-04-25 01:55:15 +00:00
}