Skip to content

Commit

Permalink
Add char input events example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerald committed Nov 6, 2020
1 parent 4e46e09 commit ff0950b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ path = "examples/input/keyboard_input.rs"
name = "keyboard_input_events"
path = "examples/input/keyboard_input_events.rs"

[[example]]
name = "char_input_events"
path = "examples/input/char_input_events.rs"

[[example]]
name = "gamepad_input"
path = "examples/input/gamepad_input.rs"
Expand Down
23 changes: 23 additions & 0 deletions examples/input/char_input_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use bevy::{input::text::CharInput, prelude::*};

fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_system(print_char_event_system.system())
.run();
}

#[derive(Default)]
struct State {
event_reader: EventReader<CharInput>,
}

/// This system prints out all char events as they come in
fn print_char_event_system(
mut state: Local<State>,
char_input_events: Res<Events<CharInput>>,
) {
for event in state.event_reader.iter(&char_input_events) {
println!("{:?}: '{}'", event, event.0);
}
}

0 comments on commit ff0950b

Please sign in to comment.