houmain / keymapper

A cross-platform context-aware key remapper.
GNU General Public License v3.0
295 stars 25 forks source link

`Backquote` being mapped to `IntlBackslash` on MacOS #150

Closed sangaline closed 3 months ago

sangaline commented 4 months ago

I'm using a US keyboard layout on MacOS that has `/~ above tab and to the left of 1 on the keyboard. When I run keymapper, this key starts acting like §/±. This happens both with the internal laptop keyboard and an external keyboard.

I modified the source to log the scan codes and found that the key in question has a scan code of 0x64 (side note: it would be convenient if there was a debug flag that did this). The configuration for the Apple scan codes in src/runtime/Key.h is:

  Backquote          = 0x35,
  IntlBackslash      = 0x64,

Given this information, I was able to work around the issue by adding this rule to my config:

IntlBackslash >> Backquote

I'm not sure if this is a bug in the code values or if the codes might differ with different keyboard layouts? I found this issue microsoft/node-native-keymap#15 which touches on something similar, but I'm still not entirely sure with respect to the scan codes.

houmain commented 4 months ago

Thanks for reporting! I was also puzzled by this in my tests (with a german keyboard). I found that only these two keys seemed to be swapped, found a ticket in the Karabiner-Elements project and so I simply added a workaround for now in src/server/unix/GrabbedDevicesMacOS.cpp line 276:

  // TODO: why are these two keys swapped?
  // https://github.com/pqrs-org/Karabiner-Elements/issues/1365#issuecomment-386801671
  if (key == Key::IntlBackslash)
    key = Key::Backquote;
  else if (key == Key::Backquote)
    key = Key::IntlBackslash;

I did not further investigate the problem yet. Currently I do not have access to a MacOS device but I would remove the workaround, if that would make it work as expected for you.

sangaline commented 4 months ago

I can confirm that Backquote works as expected for me after removing those lines (and my previous workaround in my config). I don't have a keyboard with IntlBackslash on it to test how that would behave.

houmain commented 3 months ago

The workaround is removed in 4.4.0. No keys should be swapped when for the virtual Karabiner device the same device type is selected as for the physical device (ANSI, ISO).