Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Logical Key Value #11689

Closed
Shute052 opened this issue Feb 4, 2024 · 3 comments
Closed

Unexpected Logical Key Value #11689

Shute052 opened this issue Feb 4, 2024 · 3 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@Shute052
Copy link

Shute052 commented Feb 4, 2024

Bevy version

The main Bevy (currently, commit #08654ad), but the bug actually comes from Bevy PR #10702: Update winit to 0.29

[Optional] Relevant system information

This might be able to reproduce on any machine in the version.

What you did

I am working on the updates of leafwing_input_manager to Bevy 0.13, but as the title says, the logical Key value seems to be incorrect.

Simple Case for Reproduction

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, read_keyboard_input)
        .run()
}

fn read_keyboard_input(mut keyboard_input: EventReader<KeyboardInput>) {
    for input in keyboard_input.read() {
        dbg!(input);
    }
}

What went wrong

The situation is:

  • If you just press any letter keys, e.g., W key and then you will get a KeyboardInput(logical_key: "w"), an expected lowercase w letter.
  • However, if CapsLock is activated or Shift is pressing, like normal text input, you will get a KeyboardInput(logical_key: "W"), "AN UPPERCASE W LETTER"!
@Shute052 Shute052 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 4, 2024
@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Feb 4, 2024
@alice-i-cecile
Copy link
Member

Hmm. I'm not sure if this is incorrect behavior. The logical key value seems well-suited to things like text input. Instead, we might want a to_uppercase method or the equivalent, either in Bevy or winit. Then, consumers like LWIM who want to use this for input mapping can normalize their received values.

@alice-i-cecile alice-i-cecile added S-Needs-Design This issue requires design work to think about how it would best be accomplished and removed S-Needs-Investigation This issue requires detective work to figure out what's going wrong labels Feb 4, 2024
@Shute052
Copy link
Author

Shute052 commented Feb 4, 2024

Hmm. I'm not sure if this is incorrect behavior. The logical key value seems well-suited to things like text input. Instead, we might want a to_uppercase method or the equivalent, either in Bevy or winit. Then, consumers like LWIM who want to use this for input mapping can normalize their received values.

In many game engines, logical letter keys are simply named enum variants or automatically normalized characters. I believe Bevy game developers who aren't using LWIM also have to address both cases when dealing with widely used letter keys.

@SpecificProtagonist
Copy link
Contributor

SpecificProtagonist commented Feb 4, 2024

Bevy follows the web standards for key codes and logical keys. Key codes identify the physical key location and are invariant of keyboard layout & modifiers, logical keys represent the meaning of the key.

So Bevy behaves as expected (though the distinction between the two could probably be documented better). When I press the KeyW key, whether that logically is w or W or something else depends not just on the keyboard layout, but also on whether shift, shift lock and caps lock are active (and reading Bevy's keyboard input events isn't enough to find out about whether they are) and I believe similarly on any IMEs.

@Shute052 Shute052 closed this as completed Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants