mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:
parent
db8d3651e0
commit
13f50c7a53
7 changed files with 43 additions and 37 deletions
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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!");
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue