# Apple USB keyboard aluminium MB110LL/A configuration

## dmvianna

I've spent the 24th of December trying to find the sanest solution to configure this new Apple keyboard. I'm far from satisfied. The calculator bit at the far right is mostly assigned to mouse events, and the Fn key is not detected by xev. Most other keys can be handled by xmodmap. On the bright side, the arrows, home, end, pgup, pgdown and delete (the PC delete rightwise key!) work as expected. I've tried non-generic keyboard configurations passed through xorg.conf, but this made things even worse. Any ideas?

[EDIT 1]: Oh, games-util/joystick comes with a nice toolie called evtest, which shows every keyboard event, even Fn!!!   :Very Happy: 

[EDIT 2]: Unfortunately, the keycodes reported by evtest do not match with what xmodmap actually changes... They're randomly different!   :Confused: 

[EDIT 3]: OK, so it is actually very simple: the keypad is locked in numlock off, even though the keymap recognises the key [clear] as NumLock, and the numlock LED in my laptop goes on when I press it. So it behaves exactly as described in the xorgcfg reference figure, where it shows how to move the pointer with the keyboard if the mouse is not working. Now I must find a way to be able to make numlock work...   :Neutral:  Interestingly, numlock on makes the internal keyboard of my MacBook move the pointer too, instead of letting me use the keypad numbers...   :Confused: 

[EDIT 4]: Finally, a christmas gift! Both the internal and external keypads are working as expected. Set /etc/conf.d/keymaps with

```
EXTENDED_KEYMAPS="keypad"
```

and then issue 

```
# /etc/init.d/keymap restart
```

But do so outside X, because the keymap will change substantially, and X will go crazy... You' been warned... Another thing: be sure to disable your previous .Xmodmap, because, as the keymap will change, your modifiers will point to different keys. After changing the keymap, be sure to recreate it from scratch (if you do use xmodmap).

[EDIT 5]: All that made NumLock work correctly in the console, but it is still the same in X.   :Razz: 

[EDIT 6]: It's getting warmer...   :Smile:   adding 

```
Option "XkbTypes"   "default+numpad(microsoft)"
```

 to /etc/X11/xorg.conf makes the keypad behave mostly as expected, but = and Enter are still pointer events.

[EDIT 6]: Can't reproduce it anymore. No advance in X. Argh.   :Sad: 

[EDIT 7]: getscancodes does not work in my system. AAARRRRGGGGHHH.

[EDIT 8]: Oh, finally reproduced the nice behaviour I got in Edit 4. I have to press shift+numlock to have the keypad working as expected. Now only KP_Enter is not working. Good enough for now. I' ll try to polish it later   :Wink: 

[EDIT 9]: Got it working as expected, with NumLock working without the Shift key. I just had to add (to my .Xmodmap)

```
keycode  77 = Pointer_EnableKeys

keycode 108 = KP_Enter
```

  :Twisted Evil: 

[EDIT 10]: There is a minor annoyance though. While numlock is on, the mouse can't click. Also, the numlock LED is permanently on. Oh, well, I hope either someone answers this post, or Xorg is fixed upstream...   :Razz: 

----------

## MisteR_TwO

I've got me one of those fancy apple keyboards and I like it so far (random blink disconnecting from USB aside). The keycode for the "fn" button is 484 if I remember correctly. getscancodes won't show it since it runs in X, which it's keycodes stop at 255. I got it using a program whose name I forgot, but it was run from a console outside of X, where keycodes don't matter as much.

But the last time I posted about this, I was using sabayon. Switched back to gentoo now.

Later.

----------

## deribin

Just got my Aplle keyboard. 

The only question I have is regarding "Fn" key. using xev I can't see scancode from this key and can not bind it to normal "Insert" key. 

Any suggestions?

----------

## twam

Hi!

I got als an Apple Keyboard today, in the international Version (MB110Z/A). Besides of the problem of the FN key and numlock, the key left from 1 is labeled with & and ± but it is mapped to ` and ~, and the key left oft Z is labeled with ` and ~ is mapped to < and >.

Is there a special keyboard model to choose to get this work under X11?

Regards

  Tobias

----------

## twam

showkey reports keycode 464 for the fn key.

----------

## dmvianna

 *twam wrote:*   

> Hi!
> 
> I got als an Apple Keyboard today, in the international Version (MB110Z/A). Besides of the problem of the FN key and numlock, the key left from 1 is labeled with & and ± but it is mapped to ` and ~, and the key left oft Z is labeled with ` and ~ is mapped to < and >.
> 
> Is there a special keyboard model to choose to get this work under X11?
> ...

 

I would probably use

/etc/conf.d/keymaps:

```
KEYMAP="us-acentos"

EXTENDED_KEYMAPS="keypad"

```

xorg.conf:

```
Section "InputDevice"

   Identifier  "Keyboard1"

   Driver      "kbd"

   Option       "XkbRules" "xorg"

   Option       "XkbModel" "macintosh"

   Option       "XkbLayout" "us-intl"

   Option       "XkbTypes" "default+numpad:(microsoft)"

EndSection

```

And use xmodmap to change the mapping of the keys you mentioned. Run xev to get the right keycode numbers, then place it in your ~/.xmodmap file:

~/.xmodmap

```
keycode <number> = ampersand sdg

keycode <number> =  dead_grave dead_tilde
```

You will probably need more instances to include the symbol which is supposed to appear when you press "7"+"shift" (that's where ampersand "&" is located in my keyboard) and any other misplaced characters (like "shift"+"," and "shift"+".", which is where I find "<" and ">".

Please note that in my system I use deadkeys (when I press accent keys they don't display anything until I press a letter key; when this happens, I get the letter displayed with the accent. To print the accent alone, I press its key then space). To get rid of this behavior, omit "-acentos", "-intl" and "-dead" in the examples above.

[EDIT]: Or maybe you could try this instead:

```
Option       "XkbLayout" "gr"
```

 :Wink: 

----------

## twam

Hello!

I'm already using

```
Section "InputDevice"

        Identifier     "Keyboard0"

        Driver         "keyboard"

        Option  "XkbModel"   "macintosh"

        Option  "XkbLayout" "us"

        Option  "XkbVariant" "altgr-intl"

        Option  "XkbOptions" "lv3:ralt_switch"

EndSection
```

and tried "apple" as XkbModel. But still no use of that "fn" key.

I'm already trying with ~/.xmodmap, but I thought there should be a standard configuration for that thousands of apple keyboards.  :Smile:  Besides of that, ~/.xmodmap is not executed automatically from my X11, I have to start this by hand. :/

----------

## CdR

The problem with Fn is only one -- you can not "see" scancode above 255 under X. So xev does not report it and you can not map it using xmodmap.

As far as I can understand, we need the way to replace 464 with something useful ( < 255 ).

I don't know how to do it.  :Sad: 

----------

## twam

I tried setting 464 with xmodmap, but nothing happended.

----------

## dmvianna

 *twam wrote:*   

> I thought there should be a standard configuration for that thousands of apple keyboards.  

 

Heh. I don't think Apple contacted X.org developers prior to releasing their new keyboard. The work would have been started as one of them bought one.  :Wink: 

 *twam wrote:*   

> Besides of that, ~/.xmodmap is not executed automatically from my X11, I have to start this by hand. :/

 

That is easy: http://gentoo-wiki.com/HOWTO_Autostart_Programs.

Apparently you could change the scancode of a key during boot or with an /etc/init.d/ initscript. I didn't follow that path because I couldn't get the scancode for Fn, but apparently other people did.

----------

## twam

I managed that via KDE autostart.

Your idea of changing the scancode sounds very interesting. Do you have any hints on that or where to find more information?

----------

## dmvianna

I can't remember.   :Embarassed:   I did find it before, and it led me to the getscancodes program, which didn't work on my system. Then I abandoned it.

----------

## dmvianna

I found some info, but it's not in English, so I will translate it here:

1. Leave X and go to a virtual console;

2. press Fn;

3. If you get no character after pressing it, run dmesg and you will find some info there resembling

```
atkbd.c: Unknown key pressed (translated set 2, code 0x9e on isa0060/serio0).

  atkbd.c: Use 'setkeycodes e01e <keycode>' to make it known.
```

4. Usually keycodes between 121 and 225 are not used. For example, we could use keycode 122, but to make sure it's free run

```
# getkeycodes | grep 122
```

If there's no output we can use it.

5. Now we can associate the hexadecimal code generate by the key (displayed in dmesg) and the keycode we chose with

```
# setkeycodes e01e 122
```

6. We can autorun this command upon boot.

 :Wink: 

----------

## dmvianna

The thing is, pressing Fn in my system does not return anything in dmesg. But if you get hold of the hex code for Fn, then you can set it to be recognised in X.

The source of that information also mentions that in order to dmesg to display anything, the keypress has to be recognised by the kernel. The thing is, some keyboards have proprietary ways of doing such things which are not detected by the kernel, and in those instances one can't use that method.

This does not mean that nothing can be done, though. My Fn key works on the laptop through a MacBook-tailored app called app-laptop/pommed. My guess is we will have to wait for developers to come up with an app which will bypass the kernel to recognise the Fn key, just like pommed does, in the new Apple keyboard.   :Neutral: 

[EDIT]: But then again, if you found keycode=464, it means your kernel DID detect it. So I don't know what's wrong with my system.   :Razz: 

----------

## twam

Hmm.... There's something strange here as well. I did fount the keycode 464 with showkey, but getkeycodes shows an empty table to me, which should be full :/

```
Einfache Scancodes xx (hexadezimal) und Tastencodes (dezimal).

 0x00:    0   -   -   -   -   -   -   -

 0x08:    -   -   -   -   -   -   -   -

 0x10:    -   -   -   -   -   -   -   -

 0x18:    -   -   -   -   -   -   -   -

 0x20:    -   -   -   -   -   -   -   -

 0x28:    -   -   -   -   -   -   -   -

 0x30:    -   -   -   -   -   -   -   -

 0x38:    -   -   -   -   -   -   -   -

 0x40:    -   -   -   -   -   -   -   -

 0x48:    -   -   -   -   -   -   -   -

 0x50:    -   -   -   -   -   -   -   -

 0x58:    -   -   -   -   -   -   -   -

 0x60:    -   -   -   -   -   -   -   -

 0x68:    -   -   -   -   -   -   -   -

 0x70:    -   -   -   -   -   -   -   -

 0x78:    -   -   -   -   -   -   -   -

Scancodes mit Escape e0 xx (hex).

e0 00:    -   -   -   -   -   -   -   -

e0 08:    -   -   -   -   -   -   -   -

e0 10:    -   -   -   -   -   -   -   -

e0 18:    -   -   -   -   -   -   -   -

e0 20:    -   -   -   -   -   -   -   -

e0 28:    -   -   -   -   -   -   -   -

e0 30:    -   -   -   -   -   -   -   -

e0 38:    -   -   -   -   -   -   -   -

e0 40:    -   -   -   -   -   -   -   -

e0 48:    -   -   -   -   -   -   -   -

e0 50:    -   -   -   -   -   -   -   -

e0 58:    -   -   -   -   -   -   -   -

e0 60:    -   -   -   -   -   -   -   -

e0 68:    -   -   -   -   -   -   -   -

e0 70:    -   -   -   -   -   -   -   -

e0 78:    -   -   -   -   -   -   -   -
```

Maybe this all isn't working with hid (usb) devices and only with gold AT keyboards (atkbd.c).

I'm waiting for my new MacBook and I'll test it there with the internal keyboard as well.

----------

## dmvianna

I do get an empty table too. But as I said, the MacBook inbuild keyboard works properly with pommed, Fn included, no need to fiddle.  :Neutral:  Maybe it's a limitation of the HID kernel driver, that needs to be fixed?   :Rolling Eyes: 

----------

## twam

My MacBook arrived!

Same issues here: Fn has code 464 and scancode table is empty. :/

----------

## twam

I managed to get the Fn+F1, ... Fn+F12 work on my macbook.

I had to change the dev_id of my keyboard in drivers/hid/usbhid/hid-quirks.c

Edit: Desktop is working now, too!

Update

 #define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b

in

 drivers/hid/usbhid/hid-quirks.c

to your device id. You'll get it from lsusb.

The table is still empty and Fn has keycode 464, but I can use all the Fn-Combinations.

----------

## dmvianna

 *twam wrote:*   

> I can use all the Fn-Combinations.

 

Awesome! It works here too!  :Smile: 

One last question: are you able to switch to VCs? I was able until I got the USB keyboard and a new screen. I'm not sure what is the problem, but I can't do it anymore...   :Razz: 

----------

## twam

Yes I am! But in default you have to press Control+Alt+Fn+FX or you have to set

```
echo 0x02 > /sys/module/hid/parameters/pb_fnmode
```

----------

## dmvianna

Just realised my keymap is different now that I'm using Option = "xkbmodel" "macintosh". I'll have to figure out a new keyboard layout in order to make all that work nicely as before.   :Razz: 

[EDIT]: Plus, I didn't realise that, as I am now using keycode 108 = KP_Enter (for the desktop keyboard), I am cancelling the previous keycode 108 = Pointer_Button_3 I had, so the KP_Enter button in the laptop would be used to call the root menu in Fluxbox... Things are getting clearer now.   :Mr. Green: 

[EDIT 2] VC switching fixed...   :Smile:  Some silly bug, fixed by mkdir /var/lib/xkb/compiled. Also, Option	    "XkbLayout" "us-intl" is deprecated, the new option for the same thing is  Option      "XkbLayout" "latin".

[EDIT 3] Yes, VC switching is working... but the keypad is not working on X anymore.   :Razz: 

----------

## twam

Try

```
Section "InputDevice"

        Identifier     "Keyboard0"

        Driver         "keyboard"

        Option  "XkbModel"   "pc105"

        Option  "XkbLayout" "us"

        Option  "XkbVariant" "altgr-intl"

        Option  "XkbOptions" "lv3:ralt_switch"

EndSection
```

This should be the correct successor of us-intl.

----------

## dmvianna

Nope. The keypad stopped working, and the dead keys went alive.   :Shocked: 

If you give me your reference, I could find the right config for me.   :Wink: 

----------

## twam

/usr/share/X11/xkb/rules/xorg.lst lists all valid options. 

For the keypad problem, maybe we need to set another define in the kernel files.

----------

## dmvianna

 *twam wrote:*   

> For the keypad problem, maybe we need to set another define in the kernel files.

 

Do you have the same keypad problem?

Do you use x11-misc/xkbdata or x11-misc/xkeyboard-config? I get

```
setxkbmap -model macintosh -layout us -variant intl -option lv3:ralt_switch

Error loading new keyboard description

```

same with altgr-intl...   :Confused: 

[EDIT]: Numpad issue solved! 

```
 Option      "XkbOption" "numpad:mac"

```

 But now I have to find out how to kill the dead keys again... They're alive!   :Shocked: 

[EDIT 2]: OK, a sane combination (finally): 

```
setxkbmap -model pc105 -layout us -variant intl -option numpad:mac
```

But... Then I need Fn+Control+Alt+FX to switch consoles. That is extremely uncomfortable in the desktop keyboard.   :Razz: 

[EDIT 3]: so the present xorg.conf keyboard section looks like:

```
Section "InputDevice"

        Identifier  "Keyboard1"

        Driver      "keyboard"

        Option      "XkbModel" "pc105"

        Option      "XkbLayout" "us"

        Option      "XkbVariant" "intl"

        Option      "XkbOption" "numpad:mac"

EndSection

```

----------

## twam

My numpad isn't working correctly, but I didn't noticed it yet  :Smile: 

numpad:mac didn't solve it, but I'll investige some time on this later

----------

## dmvianna

Try pressing [clear] (mapped as NumLock) before typing? If not, the keypad will work as a pointer device. Also, check http://gentoo-wiki.com/HARDWARE_Apple_MacBook#Keyboard_and_Numpad_configuration_in_X11.   :Wink:   Some keys will have to be remapped with xmodmap anyway.

----------

## twam

I sent my Device-IDs to linux-input@atrey.karlin.mff.cuni.cz and they told me, that they will be added into the tree.

So hopefully we don't need to edit anything in future kernel releases.

----------

## twam

I wrote a small patch http://linux.twam.info/patches/macbook3rd-2.6.24_rc8.patch to change the device ids and implements the correct use of the special keys. Only tested with vanilla kernel 2.6.24_rc7 and rc8.

----------

## twam

In kernel 2.6.25-rc2 support for that kind of keyboards was added, so patching is not needed anymore.  :Smile: 

----------

## dmvianna

New weird problem: I am using svn pommed, and setting the default Fn state through pommed.conf leads to opposite effects in the inbuilt and USB keyboard... Go figure. My kernel version is gentoo-sources 2.6.24-r3, with mactel-patches, and numpad stopped working again. I changed manually my device id in drivers/hid/usbhid/hid-quirks.c, not completely sure what the effect was.

[update 1]: same behavior after restoring hid-quirks.c to the original setting and downgrading to pommed-1.14.

[update 2]: numpad is fixed for the external keyboard, but not for the laptop inbuilt keyboard. Seems like xorg.conf options changed again upstream...   :Wink: 

```
   Option       "XkbModel" "macintosh"

   Option       "XkbLayout" "us"

   Option      "XkbVariant" "mac"

   Option       "XkbOption" "numpad:mac"

```

[update 3]: I figured out the problem, and found a new, perfectly working setup:

MacBook Pro keyboard:

```
Section "InputDevice"

   Identifier  "Keyboard0"

   Driver      "keyboard"

   Option       "AutoRepeat" "500 30"

   Option      "XkbModel" "macbook79"

   Option      "XkbLayout" "us"

   Option      "XkbVariant" "intl"

   Option      "XkbOption" "numpad:mac"

EndSection
```

External Apple keyboard:

```
Section "InputDevice"

   Identifier  "Keyboard1"

   Driver      "keyboard"

   Option      "XkbModel" "pc105"

   Option       "XkbLayout" "us"

   Option      "XkbVariant" "intl"

   Option      "XkbVariant" "mac"

   Option       "XkbOption" "numpad:mac"

EndSection
```

The problem was, I use xkbset to assign extra mouse buttons to the keyboard. Apparently some update in xorg or my system made it uncompatible with xkbset. Whenever I use xkbset, numpad stops working properly.   :Confused: 

[update 4]: New patch in kernel renders xkbset obsolete, relevant tweaks can be found in here and here. The second alternative is more elegant, imho.   :Smile: 

----------

## brfsa

 *dmvianna wrote:*   

> 
> 
> [update 3]: I figured out the problem, and found a new, perfectly working setup:
> 
> MacBook Pro keyboard:
> ...

 

I confirm this setup is correct.

Works great on both my macbook pro 3,1 and external apple alumm. keyboard.

Thanks for the post.

----------

