mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
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:
parent
3dd4953b97
commit
5f3a529920
2 changed files with 6 additions and 12 deletions
|
@ -1,10 +1,7 @@
|
||||||
//! Prints out all chars as they are inputted.
|
//! Prints out all chars as they are inputted.
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
input::{
|
input::keyboard::{Key, KeyboardInput},
|
||||||
keyboard::{Key, KeyboardInput},
|
|
||||||
ButtonState,
|
|
||||||
},
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,11 +12,11 @@ fn main() {
|
||||||
.run();
|
.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>) {
|
fn print_char_event_system(mut char_input_events: EventReader<KeyboardInput>) {
|
||||||
for event in char_input_events.read() {
|
for event in char_input_events.read() {
|
||||||
// Only check for characters when the key is pressed
|
// Only check for characters when the key is pressed.
|
||||||
if event.state == ButtonState::Released {
|
if !event.state.is_pressed() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Key::Character(character) = &event.logical_key {
|
if let Key::Character(character) = &event.logical_key {
|
||||||
|
|
|
@ -7,10 +7,7 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
input::{
|
input::keyboard::{Key, KeyboardInput},
|
||||||
keyboard::{Key, KeyboardInput},
|
|
||||||
ButtonState,
|
|
||||||
},
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,7 +170,7 @@ fn listen_keyboard_input_events(
|
||||||
) {
|
) {
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
// Only trigger changes when the key is first pressed.
|
// Only trigger changes when the key is first pressed.
|
||||||
if event.state == ButtonState::Released {
|
if !event.state.is_pressed() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue