Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/input/char_input_events.rs
6595 views
1
//! Prints out all chars as they are inputted.
2
3
use bevy::{
4
input::keyboard::{Key, KeyboardInput},
5
prelude::*,
6
};
7
8
fn main() {
9
App::new()
10
.add_plugins(DefaultPlugins)
11
.add_systems(Update, print_char_event_system)
12
.run();
13
}
14
15
/// This system prints out all char events as they come in.
16
fn print_char_event_system(mut char_input_events: EventReader<KeyboardInput>) {
17
for event in char_input_events.read() {
18
// Only check for characters when the key is pressed.
19
if !event.state.is_pressed() {
20
continue;
21
}
22
if let Key::Character(character) = &event.logical_key {
23
info!("{:?}: '{}'", event, character);
24
}
25
}
26
}
27
28