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`.
This commit is contained in:
Antony 2024-07-15 11:03:48 -04:00 committed by GitHub
parent 3dd4953b97
commit 5f3a529920
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 12 deletions

View file

@ -1,10 +1,7 @@
//! Prints out all chars as they are inputted.
use bevy::{
input::{
keyboard::{Key, KeyboardInput},
ButtonState,
},
input::keyboard::{Key, KeyboardInput},
prelude::*,
};
@ -15,11 +12,11 @@ fn main() {
.run();
}
/// This system prints out all char events as they come in
/// This system prints out all char events as they come in.
fn print_char_event_system(mut char_input_events: EventReader<KeyboardInput>) {
for event in char_input_events.read() {
// Only check for characters when the key is pressed
if event.state == ButtonState::Released {
// Only check for characters when the key is pressed.
if !event.state.is_pressed() {
continue;
}
if let Key::Character(character) = &event.logical_key {

View file

@ -7,10 +7,7 @@
use std::mem;
use bevy::{
input::{
keyboard::{Key, KeyboardInput},
ButtonState,
},
input::keyboard::{Key, KeyboardInput},
prelude::*,
};
@ -173,7 +170,7 @@ fn listen_keyboard_input_events(
) {
for event in events.read() {
// Only trigger changes when the key is first pressed.
if event.state == ButtonState::Released {
if !event.state.is_pressed() {
continue;
}