Function keys Magic Keyboard not bound correctly

I just bought the new Magic Keyboard. On my Mac mini with Mac OS X El Capitan the function keys worked perfectly, but on my iMac still with Mavericks the function keys are not working... F12 for instance (sound up) brings me to the Dashboard and so on.

Is it something I missed? Pressing fn isn't working either and I've checked the preference pane....


I was able to make it work on Mavericks at least when connected over the USB-to-Lightning cable by applying this patch:

--- /System/Library/Extensions/AppleTopCase.kext/Contents/PlugIns/AppleTopCaseHIDEventDriver.kext/Contents/Info.plist.orig  2017-01-10 20:28:14.000000000 +0100
+++ /System/Library/Extensions/AppleTopCase.kext/Contents/PlugIns/AppleTopCaseHIDEventDriver.kext/Contents/Info.plist   2017-01-10 20:31:55.000000000 +0100
@@ -38,6 +38,38 @@
    <string>5A2053</string>
    <key>IOKitPersonalities</key>
    <dict>
+       <key>Keyboard-Event - 615</key>
+       <dict>
+           <key>CFBundleIdentifier</key>
+           <string>com.apple.driver.AppleHIDKeyboard</string>
+           <key>CapsLockDelay</key>
+           <integer>75</integer>
+           <key>DeviceUsagePairs</key>
+           <array>
+               <dict>
+                   <key>DeviceUsage</key>
+                   <integer>6</integer>
+                   <key>DeviceUsagePage</key>
+                   <integer>1</integer>
+               </dict>
+           </array>
+           <key>FnKeyboardUsageMap</key>
+           <string>0x00070050,0x0007004a,0x00070052,0x0007004b,0x0007002a,0x0007004c,0x0007004f,0x0007004d,0x00070051,0x0007004e,0x00070028,0x00070058</string>
+           <key>FnModifierUsage</key>
+           <integer>3</integer>
+           <key>FnModifierUsagePage</key>
+           <integer>255</integer>
+           <key>IOClass</key>
+           <string>AppleHIDKeyboardEventDriverV2</string>
+           <key>IOProviderClass</key>
+           <string>IOHIDInterface</string>
+           <key>NumLockKeyboardUsageMap</key>
+           <string>0x00070029,0x00070029,0x0007002a,0x0007002a,0x0007002b,0x0007002b,0x0007003a,0x0007003a,0x0007003b,0x0007003b,0x0007003c,0x0007003c,0x0007003d,0x0007003d,0x0007003e,0x0007003e,0x0007003f,0x0007003f,0x00070040,0x00070040,0x00070041,0x00070041,0x00070042,0x00070042,0x00070043,0x00070043,0x00070044,0x00070044,0x00070045,0x00070045,0x0007004a,0x0007004a,0x0007004b,0x0007004b,0x0007004c,0x0007004c,0x0007004d,0x0007004d,0x0007004e,0x0007004e,0x0007004f,0x0007004f,0x00070050,0x00070050,0x00070051,0x00070051,0x00070052,0x00070052,0x0007000d,0x00070059,0x0007000e,0x0007005a,0x0007000f,0x0007005b,0x00070018,0x0007005c,0x0007000c,0x0007005d,0x00070012,0x0007005e,0x00070024,0x0007005f,0x00070025,0x00070060,0x00070026,0x00070061,0x00070010,0x00070062,0x00070037,0x00070063,0x00070082,0x00070082,0x000700e0,0x000700e0,0x000700e1,0x000700e1,0x000700e2,0x000700e2,0x000700e3,0x000700e3,0x000700e4,0x000700e4,0x000700e5,0x000700e5,0x000700e6,0x000700e6,0x000700e7,0x000700e7</string>
+           <key>ProductID</key>
+           <integer>615</integer>
+           <key>VendorID</key>
+           <integer>1452</integer>
+       </dict>
        <key>Keyboard-Event - 656</key>
        <dict>
            <key>CFBundleIdentifier</key>
--- /System/Library/Extensions/AppleTopCase.kext/Contents/PlugIns/AppleUSBTopCaseDriver.kext/Contents/Info.plist.orig   2017-01-10 20:27:50.000000000 +0100
+++ /System/Library/Extensions/AppleTopCase.kext/Contents/PlugIns/AppleUSBTopCaseDriver.kext/Contents/Info.plist    2017-01-10 20:44:53.000000000 +0100
@@ -38,6 +38,52 @@
    <string>5A2053</string>
    <key>IOKitPersonalities</key>
    <dict>
+       <key>USBHIDDriver</key>
+       <dict>
+           <key>CFBundleIdentifier</key>
+           <string>com.apple.driver.AppleUSBTopCaseDriver</string>
+           <key>IOClass</key>
+           <string>AppleUSBTopCaseHIDDriver</string>
+           <key>IOProviderClass</key>
+           <string>IOUSBInterface</string>
+           <key>bConfigurationValue</key>
+           <integer>1</integer>
+           <key>bInterfaceNumber</key>
+           <string>*</string>
+           <key>ProductID</key>
+           <integer>615</integer>
+           <key>idVendor</key>
+           <integer>1452</integer>
+       </dict>
+       <key>USBHIDDriver - DM</key>
+       <dict>
+           <key>CFBundleIdentifier</key>
+           <string>com.apple.driver.AppleUSBTopCaseDriver</string>
+           <key>ExtendedData</key>
+           <array>
+               <integer>50399649</integer>
+               <integer>50465185</integer>
+               <integer>50530721</integer>
+               <integer>50596257</integer>
+               <integer>61868449</integer>
+               <integer>61933985</integer>
+               <integer>61999521</integer>
+               <integer>62065057</integer>
+               <integer>62261665</integer>
+           </array>
+           <key>IOClass</key>
+           <string>AppleUSBTopCaseHIDDriver</string>
+           <key>IOProviderClass</key>
+           <string>IOUSBInterface</string>
+           <key>bConfigurationValue</key>
+           <integer>1</integer>
+           <key>bInterfaceNumber</key>
+           <string>0</string>
+           <key>ProductID</key>
+           <integer>615</integer>
+           <key>idVendor</key>
+           <integer>1452</integer>
+       </dict>
        <key>AppleTopCase</key>
        <dict>
            <key>CFBundleIdentifier</key>

like so (assuming you save the patch in a file named MagicKeyboard.patch):

sudo sh -c '(cd /; patch -p0) < MagicKeyboard.patch'

and rebuilding the kext cache using:

sudo kextcache -f -update-volume /

After reboot your Magic Keyboard should be fully functional when connected over the cable.