Expose winit's key_without_modifiers / layout-aware key data in bevy_input
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
`KeyboardInput` currently exposes two ways to identify a key:
- `logical_key` — layout-dependent; winit explicitly warns against using it
for keyboard shortcuts (https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html),
because e.g. with a Russian layout `Ctrl+C` arrives as `Key::Character("с")`.
- `key_code` — the physical key position; using it alone breaks shortcut
conventions on Latin non-QWERTY layouts (AZERTY, Dvorak, ...).
This makes it impossible to implement layout-correct keyboard shortcuts in a
principled way. #24997 was fixed with a local hybrid heuristic in
`bevy_ui_widgets::text_input` (logical key first, physical fallback for
non-ASCII), but every widget/game that needs shortcuts has to reimplement it.
Spun out of #24997 as requested by @alice-i-cecile.
## What solution would you like?
Expose winit's layout-aware key data in `bevy_input`, e.g. add a
`key_without_modifiers: Key` field to `KeyboardInput`, populated from winit's
`KeyEventExtModifierSupplement::key_without_modifiers()`.
This would let shortcut matching use the key's unmodified layout-aware
meaning, which is what native toolkits and browsers do.
## What alternative(s) have you considered?
- Keep per-widget hybrid heuristics (status quo after #24997's fix).
- A dedicated shortcut-matching helper/API in `bevy_input` built on top of
this data.
## Additional context
`key_without_modifiers` is behind winit's platform-specific
`KeyEventExtModifierSupplement` extension and is not available on every
platform (needs investigation for web/mobile), so the field may have to be
optional or best-effort.
Contributor guide
Research direction
Start in bevy_input at the KeyboardInput definition and its winit KeyEvent conversion. Investigate KeyEventExtModifierSupplement::key_without_modifiers() across the platforms noted in the issue, then expose the layout-aware value with appropriate handling where it is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100