bevy
bevy copied to clipboard
Rename `KeyCode` to `PhysicalKey`
Part of https://github.com/bevyengine/bevy/issues/11052
What this Pr addresses
In bevy 0.12, KeyCode was referring to logical key (user layout dependant key), as it changes in bevy 0.13, changing the naming makes this behavioral change more obvious to users.
Technically: it's just a rename of KeyCodeto PhysicalKey.
Controversial
More discussion on discord: https://discord.com/channels/691052431525675048/768253008416342076/1203993423506571285
We're copying winit's type, and winit's wording is KeyCode.
I agree keeping the same type name as winit makes it more obvious which type we're bringing in from winit. (in winit documentation, KeyCode is addressed as "Code representing the location of a physical key").
And there is a PhysicalKey deeper down the lower level.. (and KeyCode is a crossplatform abstraction over it).
Migration Guide
- Removed
KeyCode. If you were previously usingKeyCodeto handle logical keys (to support user's keyboard layout), you might want to reach for the eventKeyboardInputand itslogical_key, or the eventReceivedCharacter. - There is a new
Res<ButtonInput<PhysicalKey>>to handle physical keys.
It looks like your PR is a breaking change, but you didn't provide a migration guide.
Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.
Seems like the comment that's the basis of the corresponding item in #11052 mentions PhysicalKey, while the issue mentions PhysicalKeyCode. Which one should we keep?
Yeah probably right, PhysicalKey makes sense for consistency with LogicalKey
If we're going to change this, I prefer PhysicalKey, with a doc alias for KeyCode. It conveys the same information, but is shorter to type and read.
KeyCode seems a much better name for this as it's the key code send by the keyboard when you press a physical key, which may actually has something different printed on it
@mockersf in bevy 0.12 and prior versions KeyCode unfortunately meant "logical key", so flipping its meaning to "physical key" in 0.13 would be very surprising & confusing for users. Additionally, bevy just loosely wraps winit for input so we should follow their naming to avoid confusion, (which is "physical key" & "logical key")
I was initially against this. But I looked at how winit arranged their PhysicalKey. They keep both KeyCode and PhysicalKey, which I think is confusing. I prefer this proposal to that.
Logical key is Key. The physical key is PhysicalKey. I can get behind that.
@mockersf in bevy 0.12 and prior versions
KeyCodeunfortunately meant "logical key", so flipping its meaning to "physical key" in 0.13 would be very surprising & confusing for users. Additionally, bevy just loosely wraps winit for input so we should follow their naming to avoid confusion, (which is "physical key" & "logical key")
In this case I think we should consider options based on a clean slate, instead of worrying about migrations. Personally, I agree with @mockersf. KeyCode should be the code sent by the keyboard. Logical keys gets too into input mapping which I think would be better handled by a more full-featured input system like leafwing-input-manager.
Logical/physical keys seems too confusing, especially for new devs. I think KeyCode + Input Action Map is the right conceptual design.
let's trust winit and go with their naming instead of adding a new layer of confusion
Closing out: I'm content to act with @mockersf as SME-Input here and make this the call.