From bc44c8e3cd9a6c5d7a41c1fd2c19f3f96a52d3c0 Mon Sep 17 00:00:00 2001 From: Luca Bancale <43883450+sbancuz@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:30:43 +0100 Subject: [PATCH] Don't use scancodes for certain keys (#292) Co-authored-by: Raven Szewczyk --- src/main/java/org/lwjglx/input/Keyboard.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/lwjglx/input/Keyboard.java b/src/main/java/org/lwjglx/input/Keyboard.java index 411ddc1..0ce348a 100644 --- a/src/main/java/org/lwjglx/input/Keyboard.java +++ b/src/main/java/org/lwjglx/input/Keyboard.java @@ -398,7 +398,7 @@ public class Keyboard { public boolean queueOutOfOrderRelease = false; public KeyEvent(int key, int keyNonScancode, int codepoint, KeyState state, long nano) { - this.key = key; + this.key = shouldTreatAsScancode(key) ? key : keyNonScancode; this.keyNonScancode = keyNonScancode; this.codepoint = codepoint; this.state = state; @@ -410,5 +410,23 @@ public class Keyboard { ev.queueOutOfOrderRelease = this.queueOutOfOrderRelease; return ev; } + + /** + * These are all the keys where we use the actual keycodes as inputs to respect different keyboard + * layouts/remappings better + */ + public static boolean shouldTreatAsScancode(int lwjglKey) { + return switch (lwjglKey) { + // spotless:off + case Keyboard.KEY_ESCAPE, Keyboard.KEY_HOME, + Keyboard.KEY_NUMLOCK, Keyboard.KEY_CAPITAL, Keyboard.KEY_SCROLL, + Keyboard.KEY_LCONTROL , Keyboard.KEY_LSHIFT, Keyboard.KEY_LMETA, Keyboard.KEY_LMENU, + Keyboard.KEY_RCONTROL , Keyboard.KEY_RSHIFT, Keyboard.KEY_RMETA, Keyboard.KEY_RMENU + -> false; + // spotless:on + default -> true; + }; + } + } }