Skip to content

Commit

Permalink
Rename keys like LAlt to AltLeft (#8792)
Browse files Browse the repository at this point in the history
# 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`
  • Loading branch information
jim-ec authored Jun 15, 2023
1 parent db8d365 commit 13f50c7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 37 deletions.
46 changes: 26 additions & 20 deletions crates/bevy_input/src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,19 @@ pub enum KeyCode {
/// The `Kanji` key.
Kanji,

/// The `LAlt` / `Left Alt` key. Maps to `Left Option` on Mac.
LAlt,
/// The `LBracket` / `Left Bracket` key.
LBracket,
/// The `LControl` / `Left Control` key.
LControl,
/// The `LShift` / `Left Shift` key.
LShift,
/// The `LWin` / `Left Windows` key. Maps to `Left Command` on Mac.
LWin,
/// The `Left Alt` key. Maps to `Left Option` on Mac.
AltLeft,
/// The `Left Bracket` / `[` key.
BracketLeft,
/// The `Left Control` key.
ControlLeft,
/// The `Left Shift` key.
ShiftLeft,
/// The `Left Super` key.
/// 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.
Mail,
Expand Down Expand Up @@ -368,16 +371,19 @@ pub enum KeyCode {
/// The `PrevTrack` key.
PrevTrack,

/// The `RAlt` / `Right Alt` key. Maps to `Right Option` on Mac.
RAlt,
/// The `RBracket` / `Right Bracket` key.
RBracket,
/// The `RControl` / `Right Control` key.
RControl,
/// The `RShift` / `Right Shift` key.
RShift,
/// The `RWin` / `Right Windows` key. Maps to `Right Command` on Mac.
RWin,
/// The `Right Alt` key. Maps to `Right Option` on Mac.
AltRight,
/// The `Right Bracket` / `]` key.
BracketRight,
/// The `Right Control` key.
ControlRight,
/// The `Right Shift` key.
ShiftRight,
/// The `Right Super` key.
/// 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.
Semicolon,
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_winit/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::Kana => KeyCode::Kana,
winit::event::VirtualKeyCode::Kanji => KeyCode::Kanji,
winit::event::VirtualKeyCode::LAlt => KeyCode::LAlt,
winit::event::VirtualKeyCode::LBracket => KeyCode::LBracket,
winit::event::VirtualKeyCode::LControl => KeyCode::LControl,
winit::event::VirtualKeyCode::LShift => KeyCode::LShift,
winit::event::VirtualKeyCode::LWin => KeyCode::LWin,
winit::event::VirtualKeyCode::LAlt => KeyCode::AltLeft,
winit::event::VirtualKeyCode::LBracket => KeyCode::BracketLeft,
winit::event::VirtualKeyCode::LControl => KeyCode::ControlLeft,
winit::event::VirtualKeyCode::LShift => KeyCode::ShiftLeft,
winit::event::VirtualKeyCode::LWin => KeyCode::SuperLeft,
winit::event::VirtualKeyCode::Mail => KeyCode::Mail,
winit::event::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect,
winit::event::VirtualKeyCode::MediaStop => KeyCode::MediaStop,
Expand All @@ -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::Power => KeyCode::Power,
winit::event::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack,
winit::event::VirtualKeyCode::RAlt => KeyCode::RAlt,
winit::event::VirtualKeyCode::RBracket => KeyCode::RBracket,
winit::event::VirtualKeyCode::RControl => KeyCode::RControl,
winit::event::VirtualKeyCode::RShift => KeyCode::RShift,
winit::event::VirtualKeyCode::RWin => KeyCode::RWin,
winit::event::VirtualKeyCode::RAlt => KeyCode::AltRight,
winit::event::VirtualKeyCode::RBracket => KeyCode::BracketRight,
winit::event::VirtualKeyCode::RControl => KeyCode::ControlRight,
winit::event::VirtualKeyCode::RShift => KeyCode::ShiftRight,
winit::event::VirtualKeyCode::RWin => KeyCode::SuperRight,
winit::event::VirtualKeyCode::Semicolon => KeyCode::Semicolon,
winit::event::VirtualKeyCode::Slash => KeyCode::Slash,
winit::event::VirtualKeyCode::Sleep => KeyCode::Sleep,
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/fog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ fn update_system(
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);
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);
fog.color.set_g(g);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/shadow_biases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl Default for CameraController {
key_right: KeyCode::D,
key_up: KeyCode::E,
key_down: KeyCode::Q,
key_run: KeyCode::LShift,
key_run: KeyCode::ShiftLeft,
walk_speed: 10.0,
run_speed: 30.0,
friction: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl Default for CameraController {
key_right: KeyCode::D,
key_up: KeyCode::E,
key_down: KeyCode::Q,
key_run: KeyCode::LShift,
key_run: KeyCode::ShiftLeft,
mouse_key_enable_mouse: MouseButton::Left,
keyboard_key_enable_mouse: KeyCode::M,
walk_speed: 2.0,
Expand Down
4 changes: 2 additions & 2 deletions examples/input/keyboard_modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fn main() {

/// This system prints when `Ctrl + Shift + A` is pressed
fn keyboard_input_system(input: Res<Input<KeyCode>>) {
let shift = input.any_pressed([KeyCode::LShift, KeyCode::RShift]);
let ctrl = input.any_pressed([KeyCode::LControl, KeyCode::RControl]);
let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);

if ctrl && shift && input.just_pressed(KeyCode::A) {
info!("Just pressed Ctrl + Shift + A!");
Expand Down
2 changes: 1 addition & 1 deletion examples/tools/scene_viewer/camera_controller_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Default for CameraController {
key_right: KeyCode::D,
key_up: KeyCode::E,
key_down: KeyCode::Q,
key_run: KeyCode::LShift,
key_run: KeyCode::ShiftLeft,
mouse_key_enable_mouse: MouseButton::Left,
keyboard_key_enable_mouse: KeyCode::M,
walk_speed: 5.0,
Expand Down

0 comments on commit 13f50c7

Please sign in to comment.