You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Objective
While `KeyCode` is very often the correct way to interact with keyboard
input there are a bunch of cases where it isn't, notably most of the
symbols (e.g. plus, minus, different parentheses). Currently the only
way to get these is to read from `EventReader<KeyboardInput>`, but then
you'd have to redo the `ButtonInput` logic for pressed/released to e.g.
make zoom functionality that depends on plus/minus keys.
This has led to confusion previously, like
#3278
## Solution
Add a `ButtonInput<Key>` resource.
## Testing
Modified the `keyboard_input` example to test it.
## Open questions
I'm not 100% sure this is the right way forward, since it duplicates the
key processing logic and might make people use the shorter
`ButtonInput<Key>` even when it's not appropriate.
Another option is to add a new struct with both `Key` and `KeyCode`, and
use `ButtonInput` with that instead. That would make it more
explanatory, but that is a lot of churn.
The third alternative is to not do this because it's too niche.
I'll add more documentation and take it out of draft if we want to move
forward with it.
@@ -107,8 +108,12 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
107
108
)]
108
109
pubstructKeyboardInput{
109
110
/// The physical key code of the key.
111
+
///
112
+
/// This corresponds to the location of the key independent of the keyboard layout.
110
113
pubkey_code:KeyCode,
111
-
/// The logical key of the input
114
+
/// The logical key of the input.
115
+
///
116
+
/// This corresponds to the actual key taking keyboard layout into account.
112
117
publogical_key:Key,
113
118
/// The press state of the key.
114
119
pubstate:ButtonState,
@@ -148,32 +153,46 @@ pub struct KeyboardInput {
148
153
)]
149
154
pubstructKeyboardFocusLost;
150
155
151
-
/// Updates the [`ButtonInput<KeyCode>`] resource with the latest [`KeyboardInput`] events.
156
+
/// Updates the [`ButtonInput<KeyCode>`] and [`ButtonInput<Key>`] resources with the latest [`KeyboardInput`] events.
152
157
///
153
158
/// ## Differences
154
159
///
155
-
/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput<KeyCode>`] resources is that
160
+
/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput`] resources are that
156
161
/// the latter has convenient functions such as [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`] and is window id agnostic.
162
+
///
163
+
/// There is a [`ButtonInput`] for both [`KeyCode`] and [`Key`] as they are both useful in different situations, see their documentation for the details.
0 commit comments