How can I make the F-keys (F1, F2, F3, ...) work differently based on the used keyboard?

Context

I have a MacBook Pro which I regularly "dock" via USB with a DisplayLink monitor. An external USB keyboard is attached to the DisplayLink monitor.

Whenever the laptop is docked I would like to use the USB keyboard with the F-keys acting as standard function keys (F1, F2, F3, etc...) without me having to press an Fn key.

However, when I use the laptop standalone I would like to use the built-in keyboard with the F-keys triggering their special functions (Mission Control, Volume, Brightness, etc...) without me having to press an Fn key.

Question

How can I make the functions key behave differently (normal vs special functions) based on the keyboard that is connected?

What I've tried

I already use Karabiner for other tasks and thought it would be a breeze to setup the desired behaviour. Unfortunately the checkbox which governs the F-key behaviour seems to be global. I tried setting the checkmark for the USB keyboard and off for the built-in keyboard, but it seems the last setting simply prevails, regardless of keyboard device.

enter image description here

I've also tried Fluor, but that tool uses the active application as the trigger to switch behaviour, not the connected keyboard.

Answers 1

  • Turns out this is easily done in Karabiner, no script is required to check which USB device is connected.

    Instead you can set the function keys behaviour per target device directly.

    For the built in keyboard I left the mapping empty, as I want to use the media keys:
    enter image description here

    For the external USB keyboard I mapped every F-key to itself:

    enter image description here

    The systemwide behaviour of the F-keys is to use them as "special" keys and not as standard keys.

    So when I type on the internal keyboard, pressing e.g. F10 is passed onto Karabiner, it simply passes the key through and the Mac mutes the sound.
    On the USB keyboard pressing F10 is passed to Karabiner, there it is remapped onto the actual F10 keycode and that is passed on to the the application.


Related Questions