char_input_events/char_input_events.rs
1//! Prints out all chars as they are inputted.
2
3use bevy::{
4 input::keyboard::{Key, KeyboardInput},
5 prelude::*,
6};
7
8fn 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.
16fn 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}