Skip to content

Fix incorrect key mapping on macOS with vanilla ctrl detector#4808

Merged
gustovafing merged 1 commit into
GregTechCEu:1.20.1from
TonyCrane:fix-mac-ctrl
Apr 28, 2026
Merged

Fix incorrect key mapping on macOS with vanilla ctrl detector#4808
gustovafing merged 1 commit into
GregTechCEu:1.20.1from
TonyCrane:fix-mac-ctrl

Conversation

@TonyCrane
Copy link
Copy Markdown
Contributor

What

On macOS, command ⌘ is used as Ctrl, but the key code of command ⌘ is different. Instead, control ⌃ has the same key code as Ctrl.

So for those classes using GTUtil, users should press control ⌃ to represent Ctrl, which is weird.

This PR reuse vanilla MC's hasControlDown method to deal with "Ctrl" on different platforms, letting macOS users to press command ⌘ for Ctrl.

Implementation Details

Vanilla MC's hasControllDown checks platform, if on macOS, then treat GLFW_KEY_LEFT_SUPER (which is command on macOS) as "Controll":

// in net.minecraft.client.gui.screens.Screen
   public static boolean hasControlDown() {
      if (Minecraft.ON_OSX) {
         return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 343) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 347);
      } else {
         return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 341) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 345);
      }
   }

Since the vanilla MC has such an interface, I think there's no need for us to implement another one using the underlying GLFW interface.

So I replace the logic of isShiftDown isCtrlDown isAltDown with vanilla's hasShiftDown hasControlDown hasAltDown to make the code cleaner and more robust.

And unfortunately, ldlib also use GLFW's interface to check these keys in ClickData and no checks of platforms. So I write a new mixin to change the value of isCtrlClick to make sure the packet sent from client is correct.

Outcome

On macOS, users will use command as Ctrl. And on other platforms, there is no changes.

How Was This Tested

I have run runClient to ensure this works well on MacBook keyboard.

@TonyCrane TonyCrane requested a review from a team as a code owner April 23, 2026 14:10
@gustovafing gustovafing merged commit d993427 into GregTechCEu:1.20.1 Apr 28, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants