use crate::keyboard::{ElementState, KeyboardInput, VirtualKeyCode}; use bevy_app::{AppExit, Events, GetEventReader}; use legion::prelude::*; pub fn exit_on_esc_system(resources: &mut Resources) -> Box { let mut keyboard_input_event_reader = resources.get_event_reader::(); SystemBuilder::new("exit_on_esc") .read_resource::>() .write_resource::>() .build( move |_, _, (ref keyboard_input_events, ref mut app_exit_events), _| { 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); } } } }, ) }