Yong & Wendy

Remap the grave_accent_and_tilde to esc

I remapped the grave accent and tilde key to the escape key and then I remapped the F12 key to the grave accent and tilde key.


The original instructional web page is here. I’m making a copy of the instructions for safekeeping. Please give credit to the original author in the link.

Start @ Option 2: A temporary command-line solution

To create a key mapping that lasts until the next reboot, use the following command in Terminal.app:

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

Important notes:

The key codes in the command (like 0x700000035) represent specific keys on your keyboard. You can find the complete list of key codes in Apple’s developer documentation.


To remove the mapping and return to default behavior, run:

sudo hidutil property --set '{"UserKeyMapping": []}'

The main limitation of this approach is that the mapping only persists until you restart your computer.

Option 3: A persistent command-line solution

To create a key mapping that persists across reboots, we’ll complement Option 2 with LaunchDaemon that would run the command automatically at startup.


Step 1/4: Grant permissions to hidutil

First, you need to give the `hidutil` command permission to monitor input:

  1. Open System Preferences > Privacy and Security > Input Monitoring
  2. Click the ”+” button to add a new application
  3. Press Cmd + Shift + G to open the “Go to folder” dialog
  4. Enter /usr/bin/hidutil and click Open
  5. Make sure the toggle next to hidutil is turned on

Step 2/4: Create a LaunchDaemon configuration file

Create a configuration file that will run the key mapping command at startup:

sudo hx /Library/LaunchDaemons/org.example.tildeKeyMapping.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.local.KeyRemapping</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/hidutil</string>
      <string>property</string>
      <string>--set</string>
      <string>{"UserKeyMapping": [
        {
          "HIDKeyboardModifierMappingSrc": 0x700000035,
          "HIDKeyboardModifierMappingDst": 0x700000029
        },
        {
          "HIDKeyboardModifierMappingSrc": 0x700000045,
          "HIDKeyboardModifierMappingDst": 0x700000035
        }
      ]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

Tip: If you need to map different keys, you can generate the XML more easily using this online tool: hidutil-generator.netlify.app


Step 3/4: Set permissions and enable the LaunchDaemon

Set the proper permissions for the configuration file:

sudo chmod 755 /Library/LaunchDaemons/org.example.tildeKeyMapping.plist

Enable the LaunchDaemon to run at startup:

sudo launchctl bootstrap system \
  /Library/LaunchDaemons/org.example.tildeKeyMapping.plist

Disable the LaunchDaemon run this command:

sudo launchctl bootout system \
  /Library/LaunchDaemons/org.example.tildeKeyMapping.plist

“launchctl bootout” Tears down a domain or removes a service from a domain.


Step 4/4: Test your configuration

Restart your Macbook and verify that the plus-minus key now functions as the tilde key.