From 641de33e4c40ef8be35702248220a19ff16ef042 Mon Sep 17 00:00:00 2001 From: Jan Nils Ferner Date: Sat, 28 Jan 2023 23:40:37 +0100 Subject: [PATCH] Fix non-macos scancodes Former-commit-id: daf067114edda0f103717779f1f699de23c99cdc [formerly 606ea6b97bc02b39fe1fda354904fa740666c75f] Former-commit-id: 7154100d6388b135942814fcdd3b790cb50ae2ea --- src/player_control/actions/game_control.rs | 80 +++++++++++++++++++--- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/src/player_control/actions/game_control.rs b/src/player_control/actions/game_control.rs index ac005e2d..ecfd6f0c 100644 --- a/src/player_control/actions/game_control.rs +++ b/src/player_control/actions/game_control.rs @@ -53,30 +53,88 @@ pub fn get_movement(control: GameControl, input: &Res>) -> f32 { } } +// MacOS: sampled by hand +// Windows: +// Linux: generate_bindings! { GameControl::Up => [ - ScanCode(13), // W - ScanCode(126), // Up arrow + // W + ScanCode( + #[cfg(target_os = "macos")] 13, + #[cfg(target_os = "windows")] 0x11, + #[cfg(target_os = "linux")] 0x11, + ), + // Up arrow + ScanCode( + #[cfg(target_os = "macos")] 126, + #[cfg(target_os = "windows")] 0x48, + #[cfg(target_os = "linux")] 0x48, + ), ], GameControl::Down => [ - ScanCode(1), // S - ScanCode(125), // Down arrow + // S + ScanCode( + #[cfg(target_os = "macos")] 1, + #[cfg(target_os = "windows")] 0x1F, + #[cfg(target_os = "linux")] 0x1F, + ), + // Down arrow + ScanCode( + #[cfg(target_os = "macos")] 125, + #[cfg(target_os = "windows")] 0x50, + #[cfg(target_os = "linux")] 0x50, + ), ], GameControl::Left => [ - ScanCode(0), // A - ScanCode(123), // Left arrow + // A + ScanCode( + #[cfg(target_os = "macos")] 0, + #[cfg(target_os = "windows")] 0x1E, + #[cfg(target_os = "linux")] 0x1E, + ), + // Left arrow + ScanCode( + #[cfg(target_os = "macos")] 123, + #[cfg(target_os = "windows")] 0x4B, + #[cfg(target_os = "linux")] 0x4B, + ), ], GameControl::Right => [ - ScanCode(2), // D - ScanCode(124), // Right arrow + // D + ScanCode( + #[cfg(target_os = "macos")] 2, + #[cfg(target_os = "windows")] 0x20, + #[cfg(target_os = "linux")] 0x20, + ), + // Right arrow + ScanCode( + #[cfg(target_os = "macos")] 124, + #[cfg(target_os = "windows")] 0x4D, + #[cfg(target_os = "linux")] 0x4D, + ), ], GameControl::Jump => [ - ScanCode(49), // Space + // Space + ScanCode( + #[cfg(target_os = "macos")] 49, + #[cfg(target_os = "windows")] 0x39, + #[cfg(target_os = "linux")] 0x39, + ), ], GameControl::ToggleEditor => [ - ScanCode(12), // Q + // Q + ScanCode( + #[cfg(target_os = "macos")] 12, + #[cfg(target_os = "windows")] 0x10, + #[cfg(target_os = "linux")] 0x10, + ), ], GameControl::Interact => [ - ScanCode(14), // E + // E + ScanCode( + #[cfg(target_os = "macos")] 14, + #[cfg(target_os = "windows")] 0x12, + #[cfg(target_os = "linux")] 0x12, + ), ], }