Difference between revisions of "Apple Keyboard"

From ArchWiki
Jump to: navigation, search
(Added a method to fix the §<>\ problem with international aluminum apple keyboards)
(style)
 
(31 intermediate revisions by 16 users not shown)
Line 1: Line 1:
 
[[Category:Keyboards]]
 
[[Category:Keyboards]]
 
+
[[ja:Apple Keyboard]]
 +
{{Style|Continues the tradition of Apple* articles of violating [[Help:Style]] in every way imaginable}}
 
== More Information ==
 
== More Information ==
Also see this page: https://help.ubuntu.com/community/AppleKeyboard
+
For background information see this page: https://help.ubuntu.com/community/AppleKeyboard
 +
 
 +
{{Note|Some of the settings can be made permanent with a configuration file for a [[kernel module]]. For this to work, the file has to be added to FILES in [[mkinitcpio.conf]] cause the kernel module will be autoloaded while booting.}}
 +
 
 +
{{Tip|If you want to use [[sudo]] to write into a system directory you can't use shell redirection.  Use {{ic|tee}} like so
 +
$ echo 0 &#124; sudo tee /sys/module/hid_apple/parameters/iso_layout
 +
}}
 +
 
 +
==Numlock is on==
 +
 
 +
You may experience that numlock is on. The symptoms are present when only the physical keys, 7,8,9,u,i,o,j,k,l and surounding keys only work and output numbers. To fix this hit {{ic|Fn}}+{{ic|F6}} twice.
 +
 
 +
==Repeating Keys==
 +
Unpair the keyboard and then re-pair it. The trick is to hold down the power button throughout the entire pairing proccess (it's a two hand job)
  
 
==Function keys do not work==
 
==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 this behaviour, you have to change a driver setting. Do the following as root:
+
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 this behaviour, you have to change the driver setting. Do the following as root:
  
  echo 2 > /sys/module/hid_apple/parameters/fnmode
+
  # echo 2 > /sys/module/hid_apple/parameters/fnmode
  
 
If it tells you that the file doesn't exist, you probably have an older kernel and will have to do the following instead:
 
If it tells you that the file doesn't exist, you probably have an older kernel and will have to do the following instead:
  
  echo 2 > /sys/module/hid/parameters/pb_fnmode
+
  # echo 2 > /sys/module/hid/parameters/pb_fnmode
  
Place whichever command worked for you in {{ic|/etc/rc.local}} to make the setting permanent.
+
Place whatever option worked for you in {{ic|/etc/modprobe.d/hid_apple.conf}} to make the setting permanent:
  
===If the above doesn't work for you===
+
{{hc|/etc/modprobe.d/hid_apple.conf|<nowiki>
 +
options hid_apple fnmode=2
 +
</nowiki>}}
  
If hid_apple/parameters and/or hid/parameters/pb_fnmode is missing in a recent Apple Bluetooth keyboard model and recent kernel (3.4)...
+
Don't forget to add this file to FILES in [[mkinitcpio.conf]], otherwise it will not work.
  
First thing: identify your keyboard. Execute as root:
+
===If the above doesn't work for your wireless keyboard===
  hidd --show
+
 
 +
If {{ic|hid_apple/parameters}} and/or {{ic|hid/parameters/pb_fnmode}} is missing in a recent Apple Bluetooth keyboard model and kernel 3.4.
 +
 
 +
First thing: identify your keyboard. Execute as root ({{ic|hidd}} is part of package {{Pkg|bluez}} from the [[official repositories]]):
 +
  # hidd --show
  
 
You should see something like:
 
You should see something like:
Line 27: Line 47:
  
 
So with the vendor (05ac) and device (0255) ID it's easier to find out if the current kernel has support for it.
 
So with the vendor (05ac) and device (0255) ID it's easier to find out if the current kernel has support for it.
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:
+
Actually, the above device is listed in the linux kernel 3.4. If you check {{ic|drivers/hid/hid-ids.h}} you should see the following line:
 
   
 
   
 
  #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI  0x0255
 
  #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI  0x0255
  
But support for the Function Key is missing.  
+
But support for the Function Key is missing.
  
In order to fix it rebuild your kernel from abs with the following patch:
+
In order to fix it rebuild your kernel from [[abs]] with the following patch:
 
http://pastebin.com/CvFJz3Fn
 
http://pastebin.com/CvFJz3Fn
  
This bug is already reported upstream.
+
This bug is already reported upstream
 
https://bugzilla.kernel.org/show_bug.cgi?id=43135
 
https://bugzilla.kernel.org/show_bug.cgi?id=43135
 +
and part of the vanilla kernel since 3.5
  
 
==< and > have changed place with § and ½==
 
==< and > have changed place with § and ½==
  
If the '''<''' and '''>''' are switched with the '''§''' and '''½''' keys, run the following command:
+
If the '''<''' and '''>''' are switched with the '''§''' and '''½''' keys, run the following command in your graphical environment:
  
  setxkbmap -option apple:badmap
+
  $ setxkbmap -option apple:badmap
  
 
Place that command into {{ic|~/.bashrc}} file to have it run automatically when you log in.
 
Place that command into {{ic|~/.bashrc}} file to have it run automatically when you log in.
Line 74: Line 95:
  
 
First, try if the new method works for you (you have to be root)
 
First, try if the new method works for you (you have to be root)
  echo 0 | tee /sys/module/hid_apple/parameters/iso_layout
+
  # echo 0 > /sys/module/hid_apple/parameters/iso_layout
To make the changes permanent:
+
To make the changes permanent add the following line to {{ic|/etc/modprobe.d/hid_apple.conf}}:
echo options hid_apple iso_layout=0 | tee -a /etc/modprobe.d/hid_apple.conf
+
options hid_apple iso_layout=0
  
 
'''To fix this the old way, do the following:'''
 
'''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'
+
  $ 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:
 
Now try your keys. When it works, you may want the change permanently. So execute this:
  xmodmap -pke | grep " 49" >> ~/.Xmodmap
+
  $ xmodmap -pke | grep " 49" >> ~/.Xmodmap
  xmodmap -pke | grep " 94" >> ~/.Xmodmap
+
  $ xmodmap -pke | grep " 94" >> ~/.Xmodmap
 +
 
 +
==The ` and ~ keys output < and >==
 +
With the US layout, the backtick and tilde keys output lessthan or graterthan.
 +
 
 +
First, try if the new method works for you (you have to be root)
 +
# echo 0 > /sys/module/hid_apple/parameters/iso_layout
 +
To make the changes permanent add the following line to {{ic|/etc/modprobe.d/hid_apple.conf}}:
 +
options hid_apple iso_layout=0
  
 
==Media Keys==
 
==Media Keys==
Line 89: Line 118:
 
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.
 
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.
  
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.
+
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.
  
  
 
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:
 
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:
<pre>
+
{{bc|1=keycode 160 = XF86AudioMute
keycode 160 = XF86AudioMute
+
 
keycode 176 = XF86AudioRaiseVolume
 
keycode 176 = XF86AudioRaiseVolume
 
keycode 174 = XF86AudioLowerVolume
 
keycode 174 = XF86AudioLowerVolume
Line 105: Line 133:
 
keycode 212 = XF86MonBrightnessUp
 
keycode 212 = XF86MonBrightnessUp
  
keycode 204 = XF86Eject
+
keycode 204 = XF86Eject}}
</pre>
+
 
and then run {{Ic|xmodmap ~/.Xmodmap}}. Place that command in the {{ic|~/.bashrc}} file to have it run automatically when you log in.
 
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==
 
==PrintScreen and SysRq==
  
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.
+
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.
 
Both issues can be addressed by installing {{AUR|keyfuzz}} from the [[Arch User Repository]].
 
Both issues can be addressed by installing {{AUR|keyfuzz}} from the [[Arch User Repository]].
  
 
With keyfuzz installed, run the following command:
 
With keyfuzz installed, run the following command:
 
  echo "458856 99" | /usr/sbin/keyfuzz -s -d /dev/input/by-id/usb-Apple__Inc_Apple_keyboard-event-kbd
 
  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.
+
458856 (0x070068) is the scancode of {{ic|F13}}, and 99 is the keycode of {{ic|PrintScreen}}/{{ic|SysRq}}.  You can determine the scancode of a particular key with {{AUR|getscancodes}}{{Broken package link|{{aur-mirror|getscancodes}}}} from the [[AUR]], and the keycode from {{ic|/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}}.
 
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}}.
Line 122: Line 149:
 
==Treating Apple Keyboards Like Regular Keyboards==
 
==Treating Apple Keyboards Like Regular Keyboards==
  
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 want to use your Apple keyboard like a regular US-layout keyboard, with {{ic|Alt}} on the left side of {{ic|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:
  
*Adds a {{ic|/etc/modprobe.d/hid_apple.conf}} file which enables the F keys by default, as above.
+
*Adds a {{ic|/etc/modprobe.d/hid_apple.conf}} file which enables the {{ic|F}} keys by default, as above.
*Uses keyfuzz to remap F13-15 to PrintScreen/SysRq, Scroll Lock, and Pause, respectively
+
*Uses keyfuzz to remap {{ic|F13-15}} to {{ic|PrintScreen}}/{{ic|SysRq}}, {{ic|Scroll Lock}}, and {{ic|Pause}}, respectively
*Swaps the ordering of the {{Keypress|Alt}} and {{Keypress|Meta}} ({{Keypress|Command}}) keys to match all other keyboards, again using keyfuzz.
+
*Swaps the ordering of the {{ic|Alt}} and {{ic|Meta}} ({{ic|Command}}) keys to match all other keyboards, again using {{ic|/etc/modprobe.d/hid_apple.conf}}.
 
*Applies these changes automatically when you plug in your keyboard, with a [[udev]] rule.
 
*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.
+
You will need to add {{ic|/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.
 +
 
 +
==Swap the Alt key and Command key(Meta/Super)==
 +
 
 +
'''Temporarily'''
 +
 
 +
The following command will swap cmd and Alt keys with immediate effect, but restarting will reset the configuration:
 +
 
 +
$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd
 +
 
 +
'''Permanently'''
 +
 
 +
Run the following command to append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary:
 +
 
 +
$ echo options hid_apple swap_opt_cmd=1 | sudo tee -a /etc/modprobe.d/hid_apple.conf
 +
Then reboot.
 +
 
 +
==Swap the Fn key and Left Ctrl key==
 +
 
 +
While the original hid-apple module doesn't have an option to swap the fn and left ctrl keys, there is a patch adding this functionality to the module: https://github.com/free5lot/hid-apple-patched.
 +
 
 +
You could install this module from aur: {{AUR|hid-apple-patched-git}}
 +
 
 +
Once installed you can either to temporarily or permanently swap fn and left ctrl key.
 +
 
 +
'''Temporarily'''
 +
 
 +
The following command will swap fn and left ctrl keys with immediate effect, but restarting will reset the configuration:
 +
 
 +
$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_fn_leftctrl
 +
 
 +
'''Permanently'''
 +
 
 +
Run the following command to append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary:
 +
 
 +
$ echo options hid_apple swap_fn_leftctrl=1 | sudo tee -a /etc/modprobe.d/hid_apple.conf
 +
Then reboot.
 +
 
 +
 
 +
Note: This patch also provides an option to use ejectcd key as the missing delete key on Apple keyboard. Just replace {{ic|swap_fn_leftctrl}} with {{ic|ejectcd_as_delete}} in the above command to enable it.

Latest revision as of 17:58, 23 October 2015

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Continues the tradition of Apple* articles of violating Help:Style in every way imaginable (Discuss in Talk:Apple Keyboard#)

More Information

For background information see this page: https://help.ubuntu.com/community/AppleKeyboard

Note: Some of the settings can be made permanent with a configuration file for a kernel module. For this to work, the file has to be added to FILES in mkinitcpio.conf cause the kernel module will be autoloaded while booting.
Tip: If you want to use sudo to write into a system directory you can't use shell redirection. Use tee like so
$ echo 0 | sudo tee /sys/module/hid_apple/parameters/iso_layout

Numlock is on

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

Repeating Keys

Unpair the keyboard and then re-pair it. The trick is to hold down the power button throughout the entire pairing proccess (it's a two hand job)

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 this behaviour, you have to change the driver setting. Do the following as root:

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

If it tells you that the file doesn't exist, you probably have an older kernel and will have to do the following instead:

# echo 2 > /sys/module/hid/parameters/pb_fnmode

Place whatever option worked for you in /etc/modprobe.d/hid_apple.conf to make the setting permanent:

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

Don't forget to add this file to FILES in mkinitcpio.conf, otherwise it will not work.

If the above doesn't work for your wireless keyboard

If hid_apple/parameters and/or hid/parameters/pb_fnmode is missing in a recent Apple Bluetooth keyboard model and kernel 3.4.

First thing: identify your keyboard. Execute as root (hidd is part of package bluez from the official repositories):

# hidd --show

You should see something like:

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. 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.

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 part of the vanilla kernel since 3.5

< and > have changed place with § and ½

If the < and > are switched with the § and ½ keys, run the following command in your graphical environment:

$ setxkbmap -option apple:badmap

Place that command into ~/.bashrc file to have it run automatically when you log in.

You can also apply the change system-wide by creating (or editing) /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 ~/.Xmodmap file:

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

Then run xmodmap ~/.Xmodmap. This command can also go into ~/.bashrc.

< 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 > /sys/module/hid_apple/parameters/iso_layout

To make the changes permanent add the following line to /etc/modprobe.d/hid_apple.conf:

options hid_apple iso_layout=0

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:

$ xmodmap -pke | grep " 49" >> ~/.Xmodmap
$ xmodmap -pke | grep " 94" >> ~/.Xmodmap

The ` and ~ keys output < and >

With the US layout, the backtick and tilde keys output lessthan or graterthan.

First, try if the new method works for you (you have to be root)

# echo 0 > /sys/module/hid_apple/parameters/iso_layout

To make the changes permanent add the following line to /etc/modprobe.d/hid_apple.conf:

options hid_apple iso_layout=0

Media Keys

The evdev driver should produce keycodes that map to the appropriate keysyms for your media keys by default. You can confirm that by running xev in a console window and watching the console output as you press your media keys.

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.


If you have confirmed that your media keys are not producing the correct keycodes, create or edit the ~/.Xmodmap file so that it includes these lines:

keycode 160 = XF86AudioMute
keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume

keycode 144 = XF86AudioPrev
keycode 162 = XF86AudioPlay
keycode 153 = XF86AudioNext

keycode 101 = XF86MonBrightnessDown
keycode 212 = XF86MonBrightnessUp

keycode 204 = XF86Eject

and then run xmodmap ~/.Xmodmap. Place that command in the ~/.bashrc file to have it run automatically when you log in.

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. Both issues can be addressed by installing keyfuzzAUR from the Arch User Repository.

With keyfuzz installed, run the following command:

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 getscancodesAUR[broken link: archived in aur-mirror] 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 /etc/rc.local.

Treating Apple Keyboards Like Regular Keyboards

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 un-apple-keyboardAUR. Currently it only works for the aluminium USB model. The package does the following things:

  • Adds a /etc/modprobe.d/hid_apple.conf file which enables the F keys by default, as above.
  • Uses keyfuzz to remap F13-15 to PrintScreen/SysRq, Scroll Lock, and Pause, respectively
  • Swaps the ordering of the Alt and Meta (Command) keys to match all other keyboards, again using /etc/modprobe.d/hid_apple.conf.
  • 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.

Swap the Alt key and Command key(Meta/Super)

Temporarily

The following command will swap cmd and Alt keys with immediate effect, but restarting will reset the configuration:

$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd

Permanently

Run the following command to append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary:

$ echo options hid_apple swap_opt_cmd=1 | sudo tee -a /etc/modprobe.d/hid_apple.conf

Then reboot.

Swap the Fn key and Left Ctrl key

While the original hid-apple module doesn't have an option to swap the fn and left ctrl keys, there is a patch adding this functionality to the module: https://github.com/free5lot/hid-apple-patched.

You could install this module from aur: hid-apple-patched-gitAUR

Once installed you can either to temporarily or permanently swap fn and left ctrl key.

Temporarily

The following command will swap fn and left ctrl keys with immediate effect, but restarting will reset the configuration:

$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_fn_leftctrl

Permanently

Run the following command to append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary:

$ echo options hid_apple swap_fn_leftctrl=1 | sudo tee -a /etc/modprobe.d/hid_apple.conf

Then reboot.


Note: This patch also provides an option to use ejectcd key as the missing delete key on Apple keyboard. Just replace swap_fn_leftctrl with ejectcd_as_delete in the above command to enable it.