Skip to content

Expose winit's key_without_modifiers / layout-aware key data in bevy_input #25055

Description

@Farori

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?

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-FeatureA new feature, making something new possibleS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions