Difference between revisions of "Apple Keyboard"

From ArchWiki
Jump to: navigation, search
(Added a method to fix the §<>\ problem with international aluminum apple keyboards)
m (style)
 
(81 intermediate revisions by 31 users not shown)
Line 1: Line 1:
 
[[Category:Keyboards]]
 
[[Category:Keyboards]]
 +
[[ja:Apple Keyboard]]
 +
{{Related articles start}}
 +
{{Related|Extra keyboard keys}}
 +
{{Related articles end}}
  
== More Information ==
+
Some Apple keyboard models may have swapped keys or missing functionality. This article describes how to change the settings for the keyboard so that it behaves as expected.
Also see this page: https://help.ubuntu.com/community/AppleKeyboard
 
  
==Function keys do not work==
+
== Numlock is on ==
  
If your F<num> keys do not work, this is probably because the kernel driver for the keyboard has defaulted to using the media keys and requiring you to use the Fn key to get to the F<num> keys. To change this behaviour, you have to change a driver setting. Do the following as root:
+
You may find that the numlock is on. The symptoms are that only the physical keys {{ic|7}},{{ic|8}},{{ic|9}},{{ic|u}},{{ic|i}},{{ic|o}},{{ic|j}},{{ic|k}},{{ic|l}} and surrounding keys work and output numbers. To fix this hit {{ic|Fn+F6}} twice.
  
echo 2 > /sys/module/hid_apple/parameters/fnmode
+
Alternatively, set the keycodes manually using [[xmodmap]] to avoid use Numlock:
  
If it tells you that the file doesn't exist, you probably have an older kernel and will have to do the following instead:
+
keycode  90 = KP_0 KP_0 KP_0 KP_0 KP_0 KP_0
 +
keycode  87 = KP_1 KP_1 KP_1 KP_1 KP_1 KP_1
 +
keycode  88 = KP_2 KP_2 KP_2 KP_2 KP_2 KP_2
 +
keycode  89 = KP_3 KP_3 KP_3 KP_3 KP_3 KP_3
 +
keycode  83 = KP_4 KP_4 KP_4 KP_4 KP_4 KP_4
 +
keycode  84 = KP_5 KP_5 KP_5 KP_5 KP_5 KP_5
 +
keycode  85 = KP_6 KP_6 KP_6 KP_6 KP_6 KP_6
 +
keycode  79 = KP_7 KP_7 KP_7 KP_7 KP_7 KP_7
 +
keycode  80 = KP_8 KP_8 KP_8 KP_8 KP_8 KP_8
 +
keycode  81 = KP_9 KP_9 KP_9 KP_9 KP_9 KP_9
  
echo 2 > /sys/module/hid/parameters/pb_fnmode
+
== Repeating keys on a wireless keyboard ==
  
Place whichever command worked for you in {{ic|/etc/rc.local}} to make the setting permanent.
+
Unpair the keyboard and then re-pair it. The trick is to hold down the power button throughout the entire pairing process.
  
===If the above doesn't work for you===
+
== Function keys do not work ==
  
If hid_apple/parameters and/or hid/parameters/pb_fnmode is missing in a recent Apple Bluetooth keyboard model and recent kernel (3.4)...
+
If your {{ic|F<num>}} keys do not work, this is probably because the kernel driver for the keyboard has defaulted to using the media keys and requiring you to use the {{ic|Fn}} key to get to the {{ic|F<num>}} keys. To change the behavior temporarily, [[append]] {{ic|2}} to {{ic|/sys/module/hid_apple/parameters/fnmode}}.
  
First thing: identify your keyboard. Execute as root:
+
  # echo "2" > /sys/module/hid_apple/parameters/fnmode
  hidd --show
 
  
You should see something like:
+
To make the change permanent, [[Kernel_modules#Setting_module_options|set]] the {{ic|hid_apple}} {{ic|fnmode}} option to 2:
40:CA:EC:32:85:AB Apple Wireless Keyboard [05ac:0255] connected
 
  
So with the vendor (05ac) and device (0255) ID it's easier to find out if the current kernel has support for it.
+
{{hc|/etc/modprobe.d/hid_apple.conf|2=
Actually, the above device is listed in the linux kernel 3.4. If you check drivers/hid/hid-ids.h you should see the following line:
+
options hid_apple fnmode=2
+
}}
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI  0x0255
 
  
But support for the Function Key is missing.  
+
To apply the change to your initial ramdisk, in your [[Mkinitcpio#Configuration|mkinitcpio configuration]] (usually {{ic|/etc/mkinitcpio.conf}}), make sure you either have {{ic|modconf}} included in the {{ic|HOOKS}} variable or {{ic|/etc/modprobe.d/hid_apple.conf}} in the {{ic|FILES}} variable. You would then need to [[regenerate the initramfs]].
  
In order to fix it rebuild your kernel from abs with the following patch:
+
If your keyboard is model A1644, please use this [https://bugzilla.kernel.org/attachment.cgi?id=258205] patch (from this [https://bugzilla.kernel.org/show_bug.cgi?id=99881#c41]thread) to fix the function/media keys.
http://pastebin.com/CvFJz3Fn
 
  
This bug is already reported upstream.
+
== Switching Cmd and Alt/AltGr ==
https://bugzilla.kernel.org/show_bug.cgi?id=43135
 
  
==< and > have changed place with § and ½==
+
This will switch the left {{ic|Alt}} and {{ic|Cmd}} key as well as the right {{ic|Alt}}/{{ic|AltGr}} and {{ic|Cmd}} key.
  
If the '''<''' and '''>''' are switched with the '''§''' and '''½''' keys, run the following command:
+
Temporary and immediate solution:
  
  setxkbmap -option apple:badmap
+
  # echo "1" > /sys/module/hid_apple/parameters/swap_opt_cmd
  
Place that command into {{ic|~/.bashrc}} file to have it run automatically when you log in.
+
Permanent change, taking place at next reboot:
  
You can also apply the change system-wide by creating (or editing) {{ic|/etc/X11/xorg.conf.d/10-keymap.conf}} as such:
+
{{hc|/etc/modprobe.d/hid_apple.conf|2=
Section "InputClass"
+
options hid_apple swap_opt_cmd=1
    Identifier "keyboard catchall"
+
}}
    MatchIsKeyboard "true"
 
    Driver "evdev"
 
    Option "XkbOptions" "apple:badmap"
 
EndSection
 
  
 +
You then need to [[regenerate the initramfs]].
  
If the above approach doesn't seem to work, you can add these two lines to your {{ic|~/.Xmodmap}} file:
+
== < and > have changed place with § and ½ ==
 +
 
 +
If the '''<''' and '''>''' are switched with the '''§''' and '''½''' keys, [[Keyboard_configuration_in_Xorg|set the xkb option]] {{ic|apple:badmap}}, for instance by running the following command in your graphical environment:
 +
 
 +
$ setxkbmap -option apple:badmap
 +
 
 +
Alternatively, set the keycodes manually using [[xmodmap]]:
  
 
  keycode  49 = less greater less greater bar brokenbar
 
  keycode  49 = less greater less greater bar brokenbar
 
  keycode  94 = section degree section degree notsign notsign
 
  keycode  94 = section degree section degree notsign notsign
  
If you use a Canadian multilingual layout (where the "ù" and the "/" is switch) use this :
+
If you use a Canadian multilingual layout (where the "ù" and the "/" is switch) use this:
  
 
  keycode  94 = slash backslash slash backslash bar brokenbar
 
  keycode  94 = slash backslash slash backslash bar brokenbar
 
  keycode  49 = ugrave Ugrave ugrave Ugrave notsign notsign
 
  keycode  49 = ugrave Ugrave ugrave Ugrave notsign notsign
  
Then run {{Ic|xmodmap ~/.Xmodmap}}. This command can also go into {{ic|~/.bashrc}}.
+
== < and > have changed place with ^ and ° (or @ and #, or ` and ~) ==
 +
 
 +
With German layout, circumflex/degree symbol and </> are exchanged. With French layout, @/# are exchanged. With the US layout, `/~ and </> are exchanged.
 +
 
 +
To change the behavior temporarily, [[append]] {{ic|0}} to {{ic|/sys/module/hid_apple/parameters/iso_layout}}. To make the change permanent, [[Kernel_modules#Setting_module_options|set]] the {{ic|hid_apple}} {{ic|iso_layout}} option to 0.
 +
 
 +
== PrintScreen and SysRq ==
 +
 
 +
Apple Keyboards have an {{ic|F13}} key instead of a {{ic|PrintScreen}}/{{ic|SysRq}} key. This means that [[Keyboard shortcuts#Kernel|Alt+SysRq sequences]] do not work, and application actions associated with {{ic|PrintScreen}} (such as taking screenshots in many games that work under [[Wine]]) do not work. To fix this, you can add {{ic|setxkbmap -option "apple:alupckeys"}} to your {{ic|.xinitrc}}. This will map {{ic|PrintScreen}}/{{ic|SysRq}} to {{ic|F13}}, as well as {{ic|Scroll lock}} to {{ic|F14}} and {{ic|Pause}} to {{ic|F15}}.
  
==< and > have changed place with ^ and °==
+
Alternatively, follow the [[Map scancodes to keycodes]] article to map the {{ic|F13}} scancode to the {{ic|PrintScreen}}/{{ic|SysRq}} keycode, where 458856 (0x0'''70068''') is the scancode of {{ic|F13}}, and {{ic|sysrq}} is the keycode of {{ic|PrintScreen}}/{{ic|SysRq}}.
With German layout, circumflex/degree symbol and 'smaller than'/'bigger than' are exchanged.
 
  
'''The new way:'''
+
== Treating Apple keyboards like regular keyboards ==
  
First, try if the new method works for you (you have to be root)
+
Depending on the customisations you want to accomplish, there are two solutions available. You need to choose one of the other.
echo 0 | tee /sys/module/hid_apple/parameters/iso_layout
 
To make the changes permanent:
 
echo options hid_apple iso_layout=0 | tee -a /etc/modprobe.d/hid_apple.conf
 
  
'''To fix this the old way, do the following:'''
+
=== Use a patch to hid-apple ===
xmodmap -e 'keycode 49 = less greater less greater bar brokenbar bar' -e 'keycode 94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032'
 
  
Now try your keys. When it works, you may want the change permanently. So execute this:
+
While the original {{ic|hid-apple}} module does not have options to further customize the keyboard, like swapping {{ic|Fn}} and left {{ic|Ctrl}} keys or having {{ic|Alt}} on the left side of {{ic|Super}}, there is a [https://github.com/free5lot/hid-apple-patched patch] adding this functionality to the module. To install the patch, [[install]] the {{AUR|hid-apple-patched-git-dkms}} package.
xmodmap -pke | grep " 49" >> ~/.Xmodmap
 
xmodmap -pke | grep " 94" >> ~/.Xmodmap
 
  
==Media Keys==
+
In addition to the patched kernel module, a configuration file is also provided by the package at {{ic|/etc/modprobe.d/hid_apple_pclayout.conf}}, which enables PC-like layout by default:
  
The evdev driver should produce keycodes that map to the appropriate keysyms for your media keys by default. You can confirm that by running {{Ic|xev}} in a console window and watching the console output as you press your media keys.
+
* Top-row keys are normally function keys, switchable to media keys by holding Fn key, as in [[#Function keys do not work]].
 +
* Four keys at the lower left corner act as {{ic|Ctrl}}, {{ic|Fn}}, {{ic|Super}}, {{ic|Alt}}, in this order.
 +
* {{ic|Super}} and {{ic|Alt}} keys on the right are swapped.
 +
* If you have an {{ic|Ejectcd}} key, it will act as {{ic|Delete}} key.
  
For these keys to have any effect, you will have to assign actions to them. Refer to [[Extra Keyboard Keys in Xorg]] for more about that.
+
Please refer to https://github.com/free5lot/hid-apple-patched#configuration for exact meaning of each configuration options and tweaking the configuration file to suit your need.
  
 +
{{Note|Do not forget to include the configuration file in ''initramfs'' otherwise it will not work automatically after boot. Refer to [[Mkinitcpio#BINARIES and FILES]] or [[Mkinitcpio#HOOKS]] (the hook you might need is called {{ic|modconf}}) about how to do that.}}
  
If you have confirmed that your media keys are ''not'' producing the correct keycodes, create or edit the {{ic|~/.Xmodmap}} file so that it includes these lines:
+
After installation the change is not picked up by the kernel immediately. The simplest way is to just reboot your system and the new behavior should be in effect.
<pre>
 
keycode 160 = XF86AudioMute
 
keycode 176 = XF86AudioRaiseVolume
 
keycode 174 = XF86AudioLowerVolume
 
  
keycode 144 = XF86AudioPrev
+
=== Use un-apple-keyboard ===
keycode 162 = XF86AudioPlay
 
keycode 153 = XF86AudioNext
 
  
keycode 101 = XF86MonBrightnessDown
+
If you do not need all of these customizations and you do not want to compile a new module manually or using dkms, there is an AUR package {{AUR|un-apple-keyboard}} which does not rely on a new kernel module, but rather just to mappings. It enables the following features:
keycode 212 = XF86MonBrightnessUp
 
  
keycode 204 = XF86Eject
+
* The keyboard is considered as an ISO keyboard (e.g. {{ic|<}} and {{ic|>}} located at the right of the {{ic|Left Shift}} key are working like expected).
</pre>
+
* The function keys are disabled by default. You need to press the {{ic|Fn}} key in combination to trigger them. By default, the behavior are thus keys {{ic|F1}} to {{ic|F12}}
and then run {{Ic|xmodmap ~/.Xmodmap}}. Place that command in the {{ic|~/.bashrc}} file to have it run automatically when you log in.
+
* The {{ic|Alt}} and {{ic|Cmd}} keys are swapped.
 +
* {{ic|F13}} is mapped to {{ic|SYSRQ}}, {{ic|F14}} to {{ic|Scroll Lock}} and {{ic|F15}} to {{ic|Pause}}.
  
==PrintScreen and SysRq==
+
The first 3 aforementioned features are brought to you using the default linux kernel module {{ic|hid-apple}}.
  
Apple Keyboards have an F13 key instead of a PrintScreen/SysRq key. This means that [[Keyboard Shortcuts#Kernel | Alt+SysRq sequences]] do not work, and application actions associated with PrintScreen (such as taking screenshots in many games that work under [[Wine]]) do not work.
+
The last one is provided by providing a mapping to {{AUR|keyfuzz}}.
Both issues can be addressed by installing {{AUR|keyfuzz}} from the [[Arch User Repository]].
 
  
With keyfuzz installed, run the following command:
+
=== Change the Behavior Without Reboot ===
echo "458856 99" | /usr/sbin/keyfuzz -s -d /dev/input/by-id/usb-Apple__Inc_Apple_keyboard-event-kbd
+
{{Warning|If the builtin keyboard and touch pad are the only input device, beware that doing so might leave your computer in an inoperable state unless hard reboot when the second command failes.}}
458856 (0x070068) is the scancode of F13, and 99 is the keycode of PrintScreen/SysRq.  You can determine the scancode of a particular key with {{AUR|getscancodes}} from the AUR, and the keycode from /usr/include/linux/input.h.
 
  
Other versions of the Apple Aluminum Keyboard may require a slightly different device path, so adjust it as needed. You can make this change permanent by putting the command in {{ic|/etc/rc.local}}.
+
To reload the kernel module without reboot, run {{ic|rmmod hid_apple && modprobe hid_apple}}.
  
==Treating Apple Keyboards Like Regular Keyboards==
+
== Magic Keyboard does not connect ==
  
If you want to use your Apple keyboard like a regular US-layout keyboard, with Alt on the left side of Meta, you can use the AUR package {{AUR|un-apple-keyboard}}.  Currently it only works for the aluminium USB model. The package does the following things:
+
If you have a magic keyboard that will not connect to the system through the built in tools, such as the Gnome 3 bluetooth menu in settings, install {{Pkg|blueman}} and its dependencies and attempt to connect with itIf it still fails to connect, make sure you have bluetoothctl and hcitool installed.
  
*Adds a {{ic|/etc/modprobe.d/hid_apple.conf}} file which enables the F keys by default, as above.
+
== See also ==
*Uses keyfuzz to remap F13-15 to PrintScreen/SysRq, Scroll Lock, and Pause, respectively
 
*Swaps the ordering of the {{Keypress|Alt}} and {{Keypress|Meta}} ({{Keypress|Command}}) keys to match all other keyboards, again using keyfuzz.
 
*Applies these changes automatically when you plug in your keyboard, with a [[udev]] rule.
 
  
You will need to add /etc/modprobe.d/hid_apple.conf to FILES in [[mkinitcpio.conf]].  Otherwise if you boot your computer with the Apple keyboard plugged in, the F keys will not be the default.
+
* https://help.ubuntu.com/community/AppleKeyboard
 +
* https://github.com/hlechner/xmodmap-aluminium-pt-br
 +
* https://github.com/free5lot/hid-apple-patched

Latest revision as of 12:32, 15 May 2018

Some Apple keyboard models may have swapped keys or missing functionality. This article describes how to change the settings for the keyboard so that it behaves as expected.

Numlock is on

You may find that the numlock is on. The symptoms are that only the physical keys 7,8,9,u,i,o,j,k,l and surrounding keys work and output numbers. To fix this hit Fn+F6 twice.

Alternatively, set the keycodes manually using xmodmap to avoid use Numlock:

keycode  90 = KP_0 KP_0 KP_0 KP_0 KP_0 KP_0
keycode  87 = KP_1 KP_1 KP_1 KP_1 KP_1 KP_1
keycode  88 = KP_2 KP_2 KP_2 KP_2 KP_2 KP_2
keycode  89 = KP_3 KP_3 KP_3 KP_3 KP_3 KP_3
keycode  83 = KP_4 KP_4 KP_4 KP_4 KP_4 KP_4
keycode  84 = KP_5 KP_5 KP_5 KP_5 KP_5 KP_5
keycode  85 = KP_6 KP_6 KP_6 KP_6 KP_6 KP_6
keycode  79 = KP_7 KP_7 KP_7 KP_7 KP_7 KP_7
keycode  80 = KP_8 KP_8 KP_8 KP_8 KP_8 KP_8
keycode  81 = KP_9 KP_9 KP_9 KP_9 KP_9 KP_9

Repeating keys on a wireless keyboard

Unpair the keyboard and then re-pair it. The trick is to hold down the power button throughout the entire pairing process.

Function keys do not work

If your F<num> keys do not work, this is probably because the kernel driver for the keyboard has defaulted to using the media keys and requiring you to use the Fn key to get to the F<num> keys. To change the behavior temporarily, append 2 to /sys/module/hid_apple/parameters/fnmode.

# echo "2" > /sys/module/hid_apple/parameters/fnmode

To make the change permanent, set the hid_apple fnmode option to 2:

/etc/modprobe.d/hid_apple.conf
options hid_apple fnmode=2

To apply the change to your initial ramdisk, in your mkinitcpio configuration (usually /etc/mkinitcpio.conf), make sure you either have modconf included in the HOOKS variable or /etc/modprobe.d/hid_apple.conf in the FILES variable. You would then need to regenerate the initramfs.

If your keyboard is model A1644, please use this [1] patch (from this [2]thread) to fix the function/media keys.

Switching Cmd and Alt/AltGr

This will switch the left Alt and Cmd key as well as the right Alt/AltGr and Cmd key.

Temporary and immediate solution:

# echo "1" > /sys/module/hid_apple/parameters/swap_opt_cmd

Permanent change, taking place at next reboot:

/etc/modprobe.d/hid_apple.conf
options hid_apple swap_opt_cmd=1

You then need to regenerate the initramfs.

< and > have changed place with § and ½

If the < and > are switched with the § and ½ keys, set the xkb option apple:badmap, for instance by running the following command in your graphical environment:

$ setxkbmap -option apple:badmap

Alternatively, set the keycodes manually using xmodmap:

keycode  49 = less greater less greater bar brokenbar
keycode  94 = section degree section degree notsign notsign

If you use a Canadian multilingual layout (where the "ù" and the "/" is switch) use this:

keycode  94 = slash backslash slash backslash bar brokenbar
keycode  49 = ugrave Ugrave ugrave Ugrave notsign notsign

< and > have changed place with ^ and ° (or @ and #, or ` and ~)

With German layout, circumflex/degree symbol and </> are exchanged. With French layout, @/# are exchanged. With the US layout, `/~ and </> are exchanged.

To change the behavior temporarily, append 0 to /sys/module/hid_apple/parameters/iso_layout. To make the change permanent, set the hid_apple iso_layout option to 0.

PrintScreen and SysRq

Apple Keyboards have an F13 key instead of a PrintScreen/SysRq key. This means that Alt+SysRq sequences do not work, and application actions associated with PrintScreen (such as taking screenshots in many games that work under Wine) do not work. To fix this, you can add setxkbmap -option "apple:alupckeys" to your .xinitrc. This will map PrintScreen/SysRq to F13, as well as Scroll lock to F14 and Pause to F15.

Alternatively, follow the Map scancodes to keycodes article to map the F13 scancode to the PrintScreen/SysRq keycode, where 458856 (0x070068) is the scancode of F13, and sysrq is the keycode of PrintScreen/SysRq.

Treating Apple keyboards like regular keyboards

Depending on the customisations you want to accomplish, there are two solutions available. You need to choose one of the other.

Use a patch to hid-apple

While the original hid-apple module does not have options to further customize the keyboard, like swapping Fn and left Ctrl keys or having Alt on the left side of Super, there is a patch adding this functionality to the module. To install the patch, install the hid-apple-patched-git-dkmsAUR package.

In addition to the patched kernel module, a configuration file is also provided by the package at /etc/modprobe.d/hid_apple_pclayout.conf, which enables PC-like layout by default:

  • Top-row keys are normally function keys, switchable to media keys by holding Fn key, as in #Function keys do not work.
  • Four keys at the lower left corner act as Ctrl, Fn, Super, Alt, in this order.
  • Super and Alt keys on the right are swapped.
  • If you have an Ejectcd key, it will act as Delete key.

Please refer to https://github.com/free5lot/hid-apple-patched#configuration for exact meaning of each configuration options and tweaking the configuration file to suit your need.

Note: Do not forget to include the configuration file in initramfs otherwise it will not work automatically after boot. Refer to Mkinitcpio#BINARIES and FILES or Mkinitcpio#HOOKS (the hook you might need is called modconf) about how to do that.

After installation the change is not picked up by the kernel immediately. The simplest way is to just reboot your system and the new behavior should be in effect.

Use un-apple-keyboard

If you do not need all of these customizations and you do not want to compile a new module manually or using dkms, there is an AUR package un-apple-keyboardAUR which does not rely on a new kernel module, but rather just to mappings. It enables the following features:

  • The keyboard is considered as an ISO keyboard (e.g. < and > located at the right of the Left Shift key are working like expected).
  • The function keys are disabled by default. You need to press the Fn key in combination to trigger them. By default, the behavior are thus keys F1 to F12
  • The Alt and Cmd keys are swapped.
  • F13 is mapped to SYSRQ, F14 to Scroll Lock and F15 to Pause.

The first 3 aforementioned features are brought to you using the default linux kernel module hid-apple.

The last one is provided by providing a mapping to keyfuzzAUR.

Change the Behavior Without Reboot

Warning: If the builtin keyboard and touch pad are the only input device, beware that doing so might leave your computer in an inoperable state unless hard reboot when the second command failes.

To reload the kernel module without reboot, run rmmod hid_apple && modprobe hid_apple.

Magic Keyboard does not connect

If you have a magic keyboard that will not connect to the system through the built in tools, such as the Gnome 3 bluetooth menu in settings, install blueman and its dependencies and attempt to connect with it. If it still fails to connect, make sure you have bluetoothctl and hcitool installed.

See also