docs/bevy/examples/input/char_input_events.rs 708 B · 26 lines · raw · history

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 keyboard_inputs: MessageReader<KeyboardInput>) {
17 for event in keyboard_inputs.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 }