bevy/examples/input
Kristoffer Søholm 2119838e27
Add support for ButtonInput<Key> (#19684)
# 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
https://github.com/bevyengine/bevy/issues/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.
2025-06-18 20:15:03 +00:00
..
char_input_events.rs Fix inconsistency in KeyboardInput examples to match migration guide (#14185) 2024-07-15 15:03:48 +00:00
gamepad_input_events.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
gamepad_input.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
gamepad_rumble.rs Renamed EventWriter::send methods to write. (#17977) 2025-02-23 21:18:52 +00:00
keyboard_input_events.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
keyboard_input.rs Add support for ButtonInput<Key> (#19684) 2025-06-18 20:15:03 +00:00
keyboard_modifiers.rs Update winit dependency to 0.29 (#10702) 2023-12-21 07:40:47 +00:00
mouse_grab.rs Split CursorOptions off of Window (#19668) 2025-06-17 20:20:13 +00:00
mouse_input_events.rs rename touchpad to gesture, and add new gestures (#13660) 2024-06-04 12:44:25 +00:00
mouse_input.rs Mouse input accumulation (#14044) 2024-07-01 14:27:21 +00:00
text_input.rs Update text_input and virtual_time examples to use Improved Spawning API (#18249) 2025-03-11 05:47:56 +00:00
touch_input_events.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
touch_input.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00