1

I've tested this on two machines running Mavericks (10.9.4), with and without an external keyboard, and in all cases the behavior is as described below.

Under System Preferences > Keyboard > Shortcuts in the "Mission Control" section I've enabled the "Show Desktop" shortcut and assigned it to F5. Similarly, I've assigned "Show Dashboard" to F6.

Regardless of how "Use all F1, F2, etc. keys as standard function keys" is set, the fn key is ignored for these shortcuts and the shortcut action always occurs, making it impossible to get F5 and F6 to act "normally" (such as in Terminal.app). It is worth noting that the "default" shortcut keys (e.g. F3 for Mission Control, F4 for LaunchPad) do work with fn as desired/expected: holding the fn modifier while pressing those keys "flips" the behavior (depending on how the "Use all F1, F2, etc. keys" option is set).

I installed "KeyRemap4MacBook" (now called Karabiner) and enabled keyboard event debug logging with:

sudo sysctl -w keyremap4macbook.debug=1

F5 without fn key

Jul 17 09:07:54 KeyboardEventCallback [sending]: eventType 10, flags 0x00000000, key 0x0060, kbdType  46, repeat = 0
Jul 17 09:07:54 KeyboardEventCallback [sending]: eventType 11, flags 0x00000000, key 0x0060, kbdType  46, repeat = 0

F5 with fn key

Jul 17 09:07:58 KeyboardEventCallback [sending]: eventType 12, flags 0x00800000, key 0x003f, kbdType  46, repeat = 0
Jul 17 09:07:59 KeyboardEventCallback [sending]: eventType 10, flags 0x00800000, key 0x0060, kbdType  46, repeat = 0
Jul 17 09:07:59 KeyboardEventCallback [sending]: eventType 11, flags 0x00800000, key 0x0060, kbdType  46, repeat = 0
Jul 17 09:08:01 KeyboardEventCallback [sending]: eventType 12, flags 0x00000000, key 0x003f, kbdType  46, repeat = 0

And for comparison...

F1 without fn key

Jul 17 09:09:11 KeyboardEventCallback [sending]: eventType 10, flags 0x00000000, key 0x0091, kbdType  46, repeat = 0
Jul 17 09:09:11 KeyboardEventCallback [sending]: eventType 11, flags 0x00000000, key 0x0091, kbdType  46, repeat = 0

F1 with fn key

Jul 17 09:09:16 KeyboardEventCallback [sending]: eventType 12, flags 0x00800000, key 0x003f, kbdType  46, repeat = 0
Jul 17 09:09:17 KeyboardEventCallback [sending]: eventType 10, flags 0x00800000, key 0x007a, kbdType  46, repeat = 0
Jul 17 09:09:17 KeyboardEventCallback [sending]: eventType 11, flags 0x00800000, key 0x007a, kbdType  46, repeat = 0
Jul 17 09:09:19 KeyboardEventCallback [sending]: eventType 12, flags 0x00000000, key 0x003f, kbdType  46, repeat = 0

Notice that with F1, when the fn key (key code 0x3F) is down, the key code is 0x7A ("F1") instead of 0x91 ("BRIGHTNESS_DOWN"), but for F5, the key stays 0x60 ("F5").

It seems that whatever is handling the keyboard shortcuts prefpane doesn't have a way to include the state of the fn modifier.

So here's my question: is there some way to assign keyboard shortcuts to function keys so that they work like the default system shortcuts and honor the fn key as a toggle between "normal" and "shortcut" behavior?

0

Thanks to a lot of example configuration files in Karabiner (previously known as KeyRemap4MacBook), I was able to come up with the following and add it to my private.xml file to get the behavior I desired, both on an external keyboard and on the built-in keyboard on a MacBook:

<root>
<item>
    <name>F5 to Show Desktop (Fn+F5 is still F5)</name>
    <appendix>Enables F5 (Shift+F5 on laptops) as a Show Desktop shortcut</appendix>

    <identifier>private.f5_to_show_desktop</identifier>

    <autogen>--KeyToKey-- KeyCode::F5, ModifierFlag::FN, KeyCode::F5</autogen>
    <autogen>--KeyToKey-- ConsumerKeyCode::KEYBOARDLIGHT_LOW, ModifierFlag::FN, KeyCode::F5</autogen>
    <autogen>--KeyToKey-- KeyCode::F5, KeyCode::MISSION_CONTROL, ModifierFlag::COMMAND_L, Option::NOREPEAT</autogen>
    <autogen>--KeyToKey-- ConsumerKeyCode::KEYBOARDLIGHT_LOW, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT, KeyCode::MISSION_CONTROL, ModifierFlag::COMMAND_L, Option::NOREPEAT</autogen>
</item>
<item>
    <name>F6 to Show Dashboard (Fn+F6 is still F6)</name>
    <appendix>Enables F6 (Shift+F6 on laptops) as a Show Dashboard shortcut</appendix>

    <identifier>private.f6_to_show_dashboard</identifier>

    <autogen>--KeyToKey-- KeyCode::F6, ModifierFlag::FN, KeyCode::F6</autogen>
    <autogen>--KeyToKey-- ConsumerKeyCode::KEYBOARDLIGHT_HIGH, ModifierFlag::FN, KeyCode::F6</autogen>
    <autogen>--KeyToKey-- KeyCode::F6, KeyCode::DASHBOARD, Option::NOREPEAT</autogen>
    <autogen>--KeyToKey-- ConsumerKeyCode::KEYBOARDLIGHT_HIGH, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT, KeyCode::DASHBOARD, Option::NOREPEAT</autogen>
</item>
</root>

Note that the private.xml file is quickly accessible from the "Misc & Uninstall" tab of the Karabiner window, and there is a ReloadXML button on the "Change Key" tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.