Skip to content

Commit

Permalink
Merge pull request #76 from janhohenheim/scancodes
Browse files Browse the repository at this point in the history
Fix non-macos scancodes

Former-commit-id: 42e5e17 [formerly a4b7eb7]
Former-commit-id: dc60ea4
  • Loading branch information
janhohenheim authored Jan 28, 2023
2 parents 3cc0ba9 + 641de33 commit 3da1572
Showing 1 changed file with 69 additions and 11 deletions.
80 changes: 69 additions & 11 deletions src/player_control/actions/game_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,88 @@ pub fn get_movement(control: GameControl, input: &Res<Input<ScanCode>>) -> f32 {
}
}

// MacOS: sampled by hand
// Windows: <https://superuser.com/a/1454198>
// Linux: <http://www.quadibloc.com/comp/scan.htm>
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,
),
],
}

0 comments on commit 3da1572

Please sign in to comment.