Easy way to remap non-modifier keys on Mac?

I want to remap § to ` and ± to ~ on my Mac keyboard because they are located in a place I am not used to. Is there an easy way to do this?


Solution 1:

The two apps most commonly used to do this are

Ukelele

and

Karabiner

There’s a lot of other options, but these are the easiest in practice for most people to just manage their layouts easily.

Solution 2:

Remapping § to ` and ± to ~ worked on my Mac (running OS X 10.15.6) without additional software with the following code snippet.

hidutil property --set '{"UserKeyMapping":
    [{"HIDKeyboardModifierMappingSrc":0x700000035,
      "HIDKeyboardModifierMappingDst":0x700000064},
     {"HIDKeyboardModifierMappingSrc":0x700000064,
      "HIDKeyboardModifierMappingDst":0x700000035}]
}'

To do this automatically at startup, I use a launchctl script called com.user.loginscript.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.loginscript</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/hidutil</string>
        <string>property</string>
        <string>--set</string>
        <string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035, "HIDKeyboardModifierMappingDst":0x700000064}, {"HIDKeyboardModifierMappingSrc":0x700000064, "HIDKeyboardModifierMappingDst":0x700000035}]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

The file needs to be registered with a one-off execution of the following command:

launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist

See also this solution which explains how to use Automator instead of launchctl.

Solution 3:

https://github.com/tekezo/Karabiner-Elements/blob/master/usage/README.md#how-to-configure-karabiner-elements

Here is explains "EXACTLY" the problem that I am having with a simple solution.

You need to update karabiner.json and add this part:

{
    "profiles": [
        {
            "name": "Default profile",
            "selected": true,
            "simple_modifications": {
                "non_us_backslash": "grave_accent_and_tilde",
                "grave_accent_and_tilde" : "non_us_backslash"
            }
        }
    ]
}