Skip to content

Commit 5f3a529

Browse files
authored
Fix inconsistency in KeyboardInput examples to match migration guide (#14185)
# Objective - The API usage of `KeyboardInput` in the `char_input_events` and `text_input` examples don't match the [migration guide](https://bevyengine.org/learn/migration-guides/0-13-to-0-14/#deprecate-receivedcharacter). ## Solution - Check using `is_pressed` over `ButtonState::Released`.
1 parent 3dd4953 commit 5f3a529

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

examples/input/char_input_events.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//! Prints out all chars as they are inputted.
22
33
use bevy::{
4-
input::{
5-
keyboard::{Key, KeyboardInput},
6-
ButtonState,
7-
},
4+
input::keyboard::{Key, KeyboardInput},
85
prelude::*,
96
};
107

@@ -15,11 +12,11 @@ fn main() {
1512
.run();
1613
}
1714

18-
/// This system prints out all char events as they come in
15+
/// This system prints out all char events as they come in.
1916
fn print_char_event_system(mut char_input_events: EventReader<KeyboardInput>) {
2017
for event in char_input_events.read() {
21-
// Only check for characters when the key is pressed
22-
if event.state == ButtonState::Released {
18+
// Only check for characters when the key is pressed.
19+
if !event.state.is_pressed() {
2320
continue;
2421
}
2522
if let Key::Character(character) = &event.logical_key {

examples/input/text_input.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
use std::mem;
88

99
use bevy::{
10-
input::{
11-
keyboard::{Key, KeyboardInput},
12-
ButtonState,
13-
},
10+
input::keyboard::{Key, KeyboardInput},
1411
prelude::*,
1512
};
1613

@@ -173,7 +170,7 @@ fn listen_keyboard_input_events(
173170
) {
174171
for event in events.read() {
175172
// Only trigger changes when the key is first pressed.
176-
if event.state == ButtonState::Released {
173+
if !event.state.is_pressed() {
177174
continue;
178175
}
179176

0 commit comments

Comments
 (0)