diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardMixin.java index 47a64b8ce8..a174506f36 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardMixin.java @@ -30,6 +30,14 @@ public abstract class KeyboardMixin { @Inject(method = "onKey", at = @At("HEAD"), cancellable = true) public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) { if (key != GLFW.GLFW_KEY_UNKNOWN) { + // on Linux/X11 the modifier is not active when the key is pressed and still active when the key is released + // https://github.com/glfw/glfw/issues/1630 + if (action == GLFW.GLFW_PRESS) { + modifiers |= Input.getModifier(key); + } else if (action == GLFW.GLFW_RELEASE) { + modifiers &= ~Input.getModifier(key); + } + if (client.currentScreen instanceof WidgetScreen && action == GLFW.GLFW_REPEAT) { ((WidgetScreen) client.currentScreen).keyRepeated(key, modifiers); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java index c556ae32b5..b723cc70ee 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java @@ -60,4 +60,14 @@ public static void setCursorStyle(CursorStyle style) { lastCursorStyle = style; } } + + public static int getModifier(int key) { + return switch (key) { + case GLFW.GLFW_KEY_LEFT_SHIFT, GLFW.GLFW_KEY_RIGHT_SHIFT -> GLFW.GLFW_MOD_SHIFT; + case GLFW.GLFW_KEY_LEFT_CONTROL, GLFW.GLFW_KEY_RIGHT_CONTROL -> GLFW.GLFW_MOD_CONTROL; + case GLFW.GLFW_KEY_LEFT_ALT, GLFW.GLFW_KEY_RIGHT_ALT -> GLFW.GLFW_MOD_ALT; + case GLFW.GLFW_KEY_LEFT_SUPER, GLFW.GLFW_KEY_RIGHT_SUPER -> GLFW.GLFW_MOD_SUPER; + default -> 0; + }; + } }