bevy/crates/bevy_input/src/system.rs
TheRawMeatball d9b8b3e618 Add EventWriter (#1575)
This adds a `EventWriter<T>` `SystemParam` that is just a thin wrapper around `ResMut<Events<T>>`. This is primarily to have API symmetry between the reader and writer, and has the added benefit of easily improving the API later with no breaking changes.
2021-03-07 20:42:04 +00:00

23 lines
609 B
Rust

use crate::{
keyboard::{KeyCode, KeyboardInput},
ElementState,
};
use bevy_app::{
prelude::{EventReader, EventWriter},
AppExit,
};
/// Sends the AppExit event whenever the "esc" key is pressed.
pub fn exit_on_esc_system(
mut keyboard_input_events: EventReader<KeyboardInput>,
mut app_exit_events: EventWriter<AppExit>,
) {
for event in keyboard_input_events.iter() {
if let Some(key_code) = event.key_code {
if event.state == ElementState::Pressed && key_code == KeyCode::Escape {
app_exit_events.send(AppExit);
}
}
}
}