Apple - How do you make the fn keyboard button work like a Ctrl button?

  1. Download and install Karabiner

  2. Open Karabiner Elements and set the Target Device in the dropdown

  3. Map fn to left_control and left_control to fn as below

    Karabiner Elements Map fn to control


Not sure which OS this started appearing in but in macOS 10.13, this can be customized in System Preferences > Keyboard > Modifier Keys:

System Preferences > Keyboard > Modifier Keys


This is my white whale. I can't use Emacs without the control key being on the left hand side. Recently I got a new MacBook so I had a chance to do this without Karabiner.

This is what worked for me to rebind the function key to control (for the built-in keyboard only), on macOS 10.15.6.

hidutil property --matching '{ "ProductID": 0x027e }' --set '{
  "UserKeyMapping": [
    {
      "HIDKeyboardModifierMappingDst": 30064771300,
      "HIDKeyboardModifierMappingSrc": 1095216660483
    },
    {
      "HIDKeyboardModifierMappingDst": 30064771296,
      "HIDKeyboardModifierMappingSrc": 280379760050179
    }
  ]
}'

Verify it with hidutil property --matching '{ "ProductID": 0x027e }' --get "UserKeyMapping".

How I found these keycodes

I've both seen the option to change the Function (fn) Key and not seen the option to change the Function (fn) Key on the same computer, using the same version of macOS. Take it with a grain of salt, but I can consistently get the variant with the Function (fn) Key option to appear if I:

  1. Have an external keyboard attached, via a USB-Type C hub
  2. Open the Keyboard → Keyboard → Modifier Keys
  3. Lock the screen using the external keyboard
  4. Walk away for some time (wait until the computer sleeps)
  5. Wake the computer by pressing a key on the external keyboard and use Touch ID to log in
  6. Now the Modifier Keys preference has the Function (fn) Key option. While in this state, change the behaviour of the function key using the drop down list (I chose ^ Control)
  7. Copy ~/Library/Preferences/ByHost/.GlobalPreferences.${__UUID__}.plist (described here) somewhere else temporarily
  8. Convert the binary PList to XML: plutil -convert xml1 .GlobalPreferences.${__UUID__}.plist

Contents of that file are:

<?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>com.apple.keyboard.modifiermapping.1452-638-0</key>
    <array>
        <dict>
            <key>HIDKeyboardModifierMappingDst</key>
            <integer>30064771300</integer>
            <key>HIDKeyboardModifierMappingSrc</key>
            <integer>1095216660483</integer>
        </dict>
        <dict>
            <key>HIDKeyboardModifierMappingDst</key>
            <real>30064771296</real>
            <key>HIDKeyboardModifierMappingSrc</key>
            <integer>280379760050179</integer>
        </dict>
    </array>
</dict>
</plist>

This page shows up if you search for these HIDKeyboardModifierMappingSrc and says that 1095216660483 is for the left function key, 280379760050179 is for the right.

I thought I was going crazy so I took some screenshots for proof:

Modifier Keys preference pane without the Function (fn) Key option

Modifier Keys preference pane without the Function (fn) Key

Modifier Keys preference pane with the Function (fn) Key option

Modifier Keys preference pane with the Function (fn) Key

About ProductID

You can find the Product ID associated with your keyboard using the System Report button: Apple menu → System Report → Hardware → USB.

If you use the --matching parameter to hidutil using a specific Product ID, the changes will affect that piece of hardware only. For example, maybe you want to change the layout of the built-in keyboard, but not an external one.

enter image description here

Tags:

Keyboard