Rename keys like LAlt to AltLeft (#8792)

# Objective

The
[`KeyCode`](https://github.com/bevyengine/bevy/blob/main/crates/bevy_input/src/keyboard.rs#L86)
enum cases `LWin` and `RWin` are too opinionated because they are also
assigned meaning by non-Windows operating systems. macOS calls the keys
completely different.

## Solution

Match [winits
approach](https://github.com/rust-windowing/winit/blob/master/src/keyboard.rs#L1635)
naming convention.

---

## Migration Guide

Migrate by replacing:
- `LAlt` → `AltLeft`
- `RAlt` → `AltRight`
- `LBracket` → `BracketLeft`
- `RBracket` → `BracketRight`
- `LControl` → `ControlLeft`
- `RControl` → `ControlRight`
- `LShift` → `ShiftLeft`
- `RShift` → `ShiftRight`
- `LWin` → `SuperLeft`
- `RWin` → `SuperRight`
This commit is contained in:
Jim Eckerlein 2023-06-15 03:37:04 +02:00 committed by GitHub
parent db8d3651e0
commit 13f50c7a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 37 deletions

View File

@ -318,16 +318,19 @@ pub enum KeyCode {
/// The `Kanji` key. /// The `Kanji` key.
Kanji, Kanji,
/// The `LAlt` / `Left Alt` key. Maps to `Left Option` on Mac. /// The `Left Alt` key. Maps to `Left Option` on Mac.
LAlt, AltLeft,
/// The `LBracket` / `Left Bracket` key. /// The `Left Bracket` / `[` key.
LBracket, BracketLeft,
/// The `LControl` / `Left Control` key. /// The `Left Control` key.
LControl, ControlLeft,
/// The `LShift` / `Left Shift` key. /// The `Left Shift` key.
LShift, ShiftLeft,
/// The `LWin` / `Left Windows` key. Maps to `Left Command` on Mac. /// The `Left Super` key.
LWin, /// Generic keyboards usually display this key with the *Microsoft Windows* logo.
/// Apple keyboards call this key the *Command Key* and display it using the ⌘ character.
#[doc(alias("LWin", "LMeta", "LLogo"))]
SuperLeft,
/// The `Mail` key. /// The `Mail` key.
Mail, Mail,
@ -368,16 +371,19 @@ pub enum KeyCode {
/// The `PrevTrack` key. /// The `PrevTrack` key.
PrevTrack, PrevTrack,
/// The `RAlt` / `Right Alt` key. Maps to `Right Option` on Mac. /// The `Right Alt` key. Maps to `Right Option` on Mac.
RAlt, AltRight,
/// The `RBracket` / `Right Bracket` key. /// The `Right Bracket` / `]` key.
RBracket, BracketRight,
/// The `RControl` / `Right Control` key. /// The `Right Control` key.
RControl, ControlRight,
/// The `RShift` / `Right Shift` key. /// The `Right Shift` key.
RShift, ShiftRight,
/// The `RWin` / `Right Windows` key. Maps to `Right Command` on Mac. /// The `Right Super` key.
RWin, /// Generic keyboards usually display this key with the *Microsoft Windows* logo.
/// Apple keyboards call this key the *Command Key* and display it using the ⌘ character.
#[doc(alias("RWin", "RMeta", "RLogo"))]
SuperRight,
/// The `Semicolon` / `;` key. /// The `Semicolon` / `;` key.
Semicolon, Semicolon,

View File

@ -172,11 +172,11 @@ pub fn convert_virtual_key_code(virtual_key_code: winit::event::VirtualKeyCode)
winit::event::VirtualKeyCode::Grave => KeyCode::Grave, winit::event::VirtualKeyCode::Grave => KeyCode::Grave,
winit::event::VirtualKeyCode::Kana => KeyCode::Kana, winit::event::VirtualKeyCode::Kana => KeyCode::Kana,
winit::event::VirtualKeyCode::Kanji => KeyCode::Kanji, winit::event::VirtualKeyCode::Kanji => KeyCode::Kanji,
winit::event::VirtualKeyCode::LAlt => KeyCode::LAlt, winit::event::VirtualKeyCode::LAlt => KeyCode::AltLeft,
winit::event::VirtualKeyCode::LBracket => KeyCode::LBracket, winit::event::VirtualKeyCode::LBracket => KeyCode::BracketLeft,
winit::event::VirtualKeyCode::LControl => KeyCode::LControl, winit::event::VirtualKeyCode::LControl => KeyCode::ControlLeft,
winit::event::VirtualKeyCode::LShift => KeyCode::LShift, winit::event::VirtualKeyCode::LShift => KeyCode::ShiftLeft,
winit::event::VirtualKeyCode::LWin => KeyCode::LWin, winit::event::VirtualKeyCode::LWin => KeyCode::SuperLeft,
winit::event::VirtualKeyCode::Mail => KeyCode::Mail, winit::event::VirtualKeyCode::Mail => KeyCode::Mail,
winit::event::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect, winit::event::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect,
winit::event::VirtualKeyCode::MediaStop => KeyCode::MediaStop, winit::event::VirtualKeyCode::MediaStop => KeyCode::MediaStop,
@ -196,11 +196,11 @@ pub fn convert_virtual_key_code(virtual_key_code: winit::event::VirtualKeyCode)
winit::event::VirtualKeyCode::PlayPause => KeyCode::PlayPause, winit::event::VirtualKeyCode::PlayPause => KeyCode::PlayPause,
winit::event::VirtualKeyCode::Power => KeyCode::Power, winit::event::VirtualKeyCode::Power => KeyCode::Power,
winit::event::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack, winit::event::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack,
winit::event::VirtualKeyCode::RAlt => KeyCode::RAlt, winit::event::VirtualKeyCode::RAlt => KeyCode::AltRight,
winit::event::VirtualKeyCode::RBracket => KeyCode::RBracket, winit::event::VirtualKeyCode::RBracket => KeyCode::BracketRight,
winit::event::VirtualKeyCode::RControl => KeyCode::RControl, winit::event::VirtualKeyCode::RControl => KeyCode::ControlRight,
winit::event::VirtualKeyCode::RShift => KeyCode::RShift, winit::event::VirtualKeyCode::RShift => KeyCode::ShiftRight,
winit::event::VirtualKeyCode::RWin => KeyCode::RWin, winit::event::VirtualKeyCode::RWin => KeyCode::SuperRight,
winit::event::VirtualKeyCode::Semicolon => KeyCode::Semicolon, winit::event::VirtualKeyCode::Semicolon => KeyCode::Semicolon,
winit::event::VirtualKeyCode::Slash => KeyCode::Slash, winit::event::VirtualKeyCode::Slash => KeyCode::Slash,
winit::event::VirtualKeyCode::Sleep => KeyCode::Sleep, winit::event::VirtualKeyCode::Sleep => KeyCode::Sleep,

View File

@ -284,12 +284,12 @@ fn update_system(
fog.color.set_r(r); fog.color.set_r(r);
} }
if keycode.pressed(KeyCode::LBracket) { if keycode.pressed(KeyCode::BracketLeft) {
let g = (fog.color.g() - 0.1 * delta).max(0.0); let g = (fog.color.g() - 0.1 * delta).max(0.0);
fog.color.set_g(g); fog.color.set_g(g);
} }
if keycode.pressed(KeyCode::RBracket) { if keycode.pressed(KeyCode::BracketRight) {
let g = (fog.color.g() + 0.1 * delta).min(1.0); let g = (fog.color.g() + 0.1 * delta).min(1.0);
fog.color.set_g(g); fog.color.set_g(g);
} }

View File

@ -256,7 +256,7 @@ impl Default for CameraController {
key_right: KeyCode::D, key_right: KeyCode::D,
key_up: KeyCode::E, key_up: KeyCode::E,
key_down: KeyCode::Q, key_down: KeyCode::Q,
key_run: KeyCode::LShift, key_run: KeyCode::ShiftLeft,
walk_speed: 10.0, walk_speed: 10.0,
run_speed: 30.0, run_speed: 30.0,
friction: 0.5, friction: 0.5,

View File

@ -209,7 +209,7 @@ impl Default for CameraController {
key_right: KeyCode::D, key_right: KeyCode::D,
key_up: KeyCode::E, key_up: KeyCode::E,
key_down: KeyCode::Q, key_down: KeyCode::Q,
key_run: KeyCode::LShift, key_run: KeyCode::ShiftLeft,
mouse_key_enable_mouse: MouseButton::Left, mouse_key_enable_mouse: MouseButton::Left,
keyboard_key_enable_mouse: KeyCode::M, keyboard_key_enable_mouse: KeyCode::M,
walk_speed: 2.0, walk_speed: 2.0,

View File

@ -11,8 +11,8 @@ fn main() {
/// This system prints when `Ctrl + Shift + A` is pressed /// This system prints when `Ctrl + Shift + A` is pressed
fn keyboard_input_system(input: Res<Input<KeyCode>>) { fn keyboard_input_system(input: Res<Input<KeyCode>>) {
let shift = input.any_pressed([KeyCode::LShift, KeyCode::RShift]); let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = input.any_pressed([KeyCode::LControl, KeyCode::RControl]); let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
if ctrl && shift && input.just_pressed(KeyCode::A) { if ctrl && shift && input.just_pressed(KeyCode::A) {
info!("Just pressed Ctrl + Shift + A!"); info!("Just pressed Ctrl + Shift + A!");

View File

@ -48,7 +48,7 @@ impl Default for CameraController {
key_right: KeyCode::D, key_right: KeyCode::D,
key_up: KeyCode::E, key_up: KeyCode::E,
key_down: KeyCode::Q, key_down: KeyCode::Q,
key_run: KeyCode::LShift, key_run: KeyCode::ShiftLeft,
mouse_key_enable_mouse: MouseButton::Left, mouse_key_enable_mouse: MouseButton::Left,
keyboard_key_enable_mouse: KeyCode::M, keyboard_key_enable_mouse: KeyCode::M,
walk_speed: 5.0, walk_speed: 5.0,