Difference between revisions of "Apple Keyboard"

From ArchWiki
Jump to: navigation, search
(Added a method to fix the §<>\ problem with international aluminum apple keyboards)
(Cleanup the description about how to treat apple keyboards like regular keyboards. Replace unmaintained un-apple-keyboard (last updated two years ago) with hid-apple-patched-git-dkms)
 
(68 intermediate revisions by 26 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 7,8,9,u,i,o,j,k,l and surrounding keys work and output numbers. To fix this hit {{ic|Fn}}+{{ic|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, [[Help:Reading#Append.2C_add.2C_create.2C_edit|append]] {{ic|2}} to {{ic|/sys/module/hid_apple/parameters/fnmode}}. To make the change permanent, [[Kernel_modules#Setting_module_options|set]] the {{ic|hid_apple}} {{ic|fnmode}} option to 2.
  
First thing: identify your keyboard. Execute as root:
+
== < and > have changed place with § and ½ ==
hidd --show
 
  
You should see something like:
+
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:
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.
+
$ setxkbmap -option apple:badmap
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:
 
 
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI  0x0255
 
  
But support for the Function Key is missing.
+
Alternatively, set the keycodes manually using [[xmodmap]]:
 
 
In order to fix it rebuild your kernel from abs with the following patch:
 
http://pastebin.com/CvFJz3Fn
 
 
 
This bug is already reported upstream.
 
https://bugzilla.kernel.org/show_bug.cgi?id=43135
 
 
 
==< and > have changed place with § and ½==
 
 
 
If the '''<''' and '''>''' are switched with the '''§''' and '''½''' keys, run the following command:
 
 
 
setxkbmap -option apple:badmap
 
 
 
Place that command into {{ic|~/.bashrc}} file to have it run automatically when you log in.
 
 
 
You can also apply the change system-wide by creating (or editing) {{ic|/etc/X11/xorg.conf.d/10-keymap.conf}} as such:
 
Section "InputClass"
 
    Identifier "keyboard catchall"
 
    MatchIsKeyboard "true"
 
    Driver "evdev"
 
    Option "XkbOptions" "apple:badmap"
 
EndSection
 
 
 
 
 
If the above approach doesn't seem to work, you can add these two lines to your {{ic|~/.Xmodmap}} file:
 
  
 
  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 ~) ==
 
 
==< and > have changed place with ^ and °==
 
With German layout, circumflex/degree symbol and 'smaller than'/'bigger than' are exchanged.
 
 
 
'''The new way:'''
 
 
 
First, try if the new method works for you (you have to be root)
 
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:'''
 
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:
+
With German layout, circumflex/degree symbol and </> are exchanged. With French layout, @/# are exchanged. With the US layout, `/~ and </> are exchanged.
xmodmap -pke | grep " 49" >> ~/.Xmodmap
 
xmodmap -pke | grep " 94" >> ~/.Xmodmap
 
  
==Media Keys==
+
To change the behavior temporarily, [[Help:Reading#Append.2C_add.2C_create.2C_edit|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.
  
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.
+
== PrintScreen and SysRq ==
  
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.
+
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}}.
  
 +
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}}.
  
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:
+
== Treating Apple keyboards like regular keyboards ==
<pre>
 
keycode 160 = XF86AudioMute
 
keycode 176 = XF86AudioRaiseVolume
 
keycode 174 = XF86AudioLowerVolume
 
  
keycode 144 = XF86AudioPrev
+
{{Warning|Another package {{AUR|un-apple-keyboard}} also provides similar functionality, but is no longer actively maintained. Thus it is advised to use the following package.}}
keycode 162 = XF86AudioPlay
 
keycode 153 = XF86AudioNext
 
  
keycode 101 = XF86MonBrightnessDown
+
While the original {{ic|hid-apple}} module doesn't 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.
keycode 212 = XF86MonBrightnessUp
 
  
keycode 204 = XF86Eject
+
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:
</pre>
 
and then run {{Ic|xmodmap ~/.Xmodmap}}. Place that command in the {{ic|~/.bashrc}} file to have it run automatically when you log in.
 
  
==PrintScreen and SysRq==
+
* 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.
  
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.
+
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.
Both issues can be addressed by installing {{AUR|keyfuzz}} from the [[Arch User Repository]].
 
  
With keyfuzz installed, run the following command:
+
{{Note| Don't forget to include the configuration file in ''initramfs'' otherwise it won't 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.}}
echo "458856 99" | /usr/sbin/keyfuzz -s -d /dev/input/by-id/usb-Apple__Inc_Apple_keyboard-event-kbd
 
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}}.
+
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.
  
==Treating Apple Keyboards Like Regular Keyboards==
+
=== 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.}}
  
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:
+
To reload the kernel module without reboot, run {{ic|sudo rmmod hid_apple && sudo modprobe hid_apple}}.
  
*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 20:10, 11 June 2017

Related articles

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. To make the change permanent, set the hid_apple fnmode option to 2.

< 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

Warning: Another package un-apple-keyboardAUR also provides similar functionality, but is no longer actively maintained. Thus it is advised to use the following package.

While the original hid-apple module doesn't 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: Don't forget to include the configuration file in initramfs otherwise it won't 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.

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 sudo rmmod hid_apple && sudo modprobe hid_apple.

See also