Tag/tag.png

Content Cleanup Required
This article should be cleaned-up to follow the content standards in the Wiki Guide. More info...

Tag/tag.png

Needs Updating
This article needs updating to include the latest versions of Ubuntu. More info...

Preface

Since Ubuntu 8.04 (Hardy Heron) the USB aluminum Apple Keyboard has not worked correctly. A change was added to the Ubuntu Linux kernel to make Apple MacBook keyboards gain additional functionality to their limited laptop style keyboard (Ubuntu bug #162083). Unfortunately this code change has some side effects for owners of the full size USB aluminum Apple Keyboard:

  • Function keys have media functions as default (as the printing on the keycaps indicates). To access the regular F-key functionality, the "fn" key must be pressed and held (except for F5 and F6, which are inverted in this respect). (Ubuntu bug #201711)

  • On international (non-US) keyboards, two keys are swapped with respect to the printing on the keycaps. (Ubuntu bug #214786)

Both issues may be straightened out with two configurable module parameters (http://bugzilla.kernel.org/show_bug.cgi?id=10818), as shown below.

To make the keyboard behave more like a standard PC keyboard (but against the orinal printing on the keycaps), additional steps are neceessary:

  • Map SysRQ, Scoll Lock, and Pause keys to F13-F15: This still requires a patch that adds a configurable option to the kernel module, or a "keyfuzz" workaround (#262408).

  • Swap the cmd and super keys: (hid_apple patch) or keyfuzz workaround.

A tar archive containing all workarounds can be found at (un-apple-keyboard)

If you would like to have a better integration, please help by enhancing the patches to implement proper module parameters, and submitting them to the upstream kernel developers. See also: Trouble With Apple Keyboard On Ubuntu

To find the the keycode of any key that you want to modify, simply run in a terminal

xev | sed -n 's/^.*keycode *\([0-9]\+\).*$/keycode \1 = /p'

Then you can find the List of Keysyms Recognised by Xmodmap:

http://wiki.linuxquestions.org/wiki/List_of_Keysyms_Recognised_by_Xmodmap

http://wiki.linuxquestions.org/wiki/ConfiguRing_keyBoards

Default Behavior

This section describe the default behavior of every Apple keyboard.

Apple slim aluminum keyboard (0220)

wired_1_20070813a.jpg

  • Characters that are not printed on the keycaps (~,{},[],...) can still be generated as on a standard PC keyboard.
  • Even if the @ is printed on another keycap as on the standard PC layout, that key will only behave like the standard PC layout key and not generate the @. Use your localized standard PC layout key (combination) to generate the @.
  • 'fn'+'F-Key' -> triggers the regular F-Key

  • 'fn'+'Enter' -> Insert

  • 'fn'+'Backspace' -> Delete

  • 'fn'+'Up' -> PageUp

  • 'fn'+'Down' -> PageDown

  • 'fn'+'Left' -> Home

  • 'fn'+'Right' -> End

  • 'Clear' behaves like 'NumLock' (Numlock may also be switched by pressing fn-F6 twice)

(See #262408 as there is patch submit to map F13, F14 and F15 to the otherwise missing PrintScreen, ScrollLock and Pause keys.)

Corrections

Change Function Key behavior

This section of the document describe how to change the behavior of 'fn' key to better match what user expect. (See #201711, #162083)

Here a description of each behavior :

  • 0 = disabled : Disable the 'fn' key. Pressing 'fn'+'F8' will behave like you only press 'F8'
  • 1 = fkeyslast : Function keys are used as last key. Pressing 'F8' key will act as a special key. Pressing 'fn'+'F8' will behave like a F8.
  • 2 = fkeysfirst : Function keys are used as first key. Pressing 'F8' key will behave like a F8. Pressing 'fn'+'F8' will act as special key (play/pause).

Ubuntu 9.04 to 12.04 LTS (Precise Pangolin)

Temporarily

The following command will change the behaviour of 'fn' key with immediate effect, but restarting will reset the configuration:

$ echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode

(The meaning of fnmode values is as described in the preceding section.)

Permanently

Methods described in this section will change the behavior permanently. There are several ways to proceed with this modification. Each sub-section describes one way to permanently change the configuration.

With .conf file (Recommended)

1. 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 fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf

2. Trigger copying the configuration into the initramfs bootfile.

$ sudo update-initramfs -u -k all

3. Optionally, reboot

$ sudo reboot

With sysfs.conf

1. Edit the /etc/sysfs.conf file, creating it if necessary.

gksudo gedit /etc/sysfs.conf

2. Add this lines to the end of the file.

module/hid_apple/parameters/fnmode = 2

3. Reboot

With rc.local

This methods simply automatically applies during startup the technique used to change fnmode temporarily.

1. Edit the /etc/rc.local file.

gksudo gedit /etc/rc.local

2. Add this line near the end of the file, before the "exit" line:

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

3. Reboot

Ubuntu 8.10 (Intrepid Ibex)

Temporarily

With immediate effect, try

sudo bash
echo 2 > /sys/module/hid/parameters/pb_fnmode
exit

Permanently

1. Edit the file /etc/modprobe.d/options, e.g.:

gksudo gedit /etc/modprobe.d/options

2. Add the line:

options hid pb_fnmode=2

3. Save the file and execute the following command:

sudo update-initramfs -u

4. Reboot

Alternatively, you can modify /etc/rc.local to similar effect.

* Edit the /etc/rc.local file:

gksudo gedit /etc/rc.local

* Add this line to the end of the file:

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

Alternatively, you can modify /etc/sysfs.conf to similar effect.

* Edit the /etc/sysfs.conf file:

gksudo gedit /etc/sysfs.conf

* Add this lines to the end of the file:

module/hid/parameters/pb_fnmode = 2

Correcting swapped keys and wrong keymaps for international (non-US) keyboards

This section describe how to fix the issue related to the swapped key when using international keyboard. (See #214786 and (See 1043336))

Ubuntu 11.10 up to recent

Temporarily

The following command will have immediate effect, but rebooting will reset the configuration:

$ echo 0 | sudo tee /sys/module/hid_apple/parameters/iso_layout

(The meaning of fnmode values is as described in the preceding section.)

Permanently

1. Append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary:

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

2. Trigger copying the configuration into the initramfs bootfile.

$ sudo update-initramfs -u -k all

3. Optionally, reboot

$ sudo reboot

Ubuntu 11.4 (Natty Narwhal)

* Create a new file ./.Xmodmap

gedit ./.Xmodmap

* Paste these two lines into the file

keycode 49 = less greater less greater bar brokenbar bar 
keycode 94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032

* For spanish keyboards use these lines instead:

keycode 49 = less greater less greater bar brokenbar bar 
keycode 94 = U000AA degree U000AA degree backslash backslash backslash

* For italian keyboards:

keycode 49 = less greater guillemotleft guillemotright guillemotleft guillemotright
keycode 94 = backslash bar notsign brokenbar notsign brokenbar

* For Hungarian keyboards: This fixes the layout if 0 and í keys are swapped:

keycode 49 = iacute Iacute backslash bar less greater
keycode 94 = 0 section doublelowquotemark rightdoublequotemark notsign notsign

* For Swiss keyboards: If you use a Swiss keyboard with a numpad there is one wrong keymap more. In Switzerland keyboards have a period (.) instead of a comma (,) on numpad next to zero (0). Also there is something weird with the default mapping of the upper left key below "ESC". This bug was recently reported at: Bug #1043336

keycode 49 = less greater less greater bar brokenbar bar 

! special section for Switzerland
keycode 91 = period period
keycode 94 = section degree

To apply the commands you can log out and log in or either run:

xmodmap ~/.Xmodmap

Ubuntu 9.10 (Karmic Koala)

* Edit your ./.xsession file:

gedit ./.xsession

* Insert this line as the second line of the file (after the first line which is probably #!/bin/sh):

xmodmap -e 'keycode 49 = less greater less greater bar brokenbar bar' -e 'keycode 94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032'

* For spanish keyboards:

xmodmap -e 'keycode 49 = less greater less greater bar brokenbar bar' -e 'keycode 94 = U000AA degree U000AA degree backslash backslash backslash'

You will have to relogin or reboot. The <> and ^° key should now be in the correct position.

Ubuntu 9.04 (Jaunty Jackalope)

Need to confirm if the problem persist as there is modification done in the kernel to fix the problem.

Ubuntu 8.10 (Intrepid Ibex)

1. Open the 'System->Preferences->Keyboard' dialog 2. Choose the 'Layouts' tab 3. Press 'Layout Options...' 4. Navigate to 'Miscellaneous compatibility options' 5. Enable the option: Swap keycodes of two keys when Mac keyboards are misdetected by kernel.

Mapping keys (Insert, Alt, Cmd, etc.)

This section describes some (deprciateed) xmodmap workarounds to change the mapping of key to better match PC's keyboard. e.g.: Swap the Alt key and Command key. The idea is to make the keyboard work more like a normal PC keyboard.

Ubuntu 13.10 (maybe also earlier)

Swap Cmd and Alt keys

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

Methods described in this section will change the behavior permanently. There are several ways to proceed with this modification. Each sub-section describes one way to permanently change the configuration.

With .conf file (Recommended)

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

2. Trigger copying the configuration into the initramfs bootfile.

$ sudo update-initramfs -u -k all

3. Optionally, reboot

$ sudo reboot

With sysfs.conf

1. Edit the /etc/sysfs.conf file, creating it if necessary.

gksudo gedit /etc/sysfs.conf

2. Add this lines to the end of the file.

module/hid_apple/parameters/swap_opt_cmd = 1

3. Reboot

With rc.local

This methods simply automatically applies during startup the technique used to change swap_opt_cmd temporarily.

1. Edit the /etc/rc.local file.

gksudo gedit /etc/rc.local

2. Add this line near the end of the file, before the "exit" line:

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

3. Reboot

Swap Fn and Left Ctrl key

There is a patch adding the functionality to swap the fn and left ctrl key to the hid-apple module, but not yet included in the mainline kernel. The repository on Github also includes a install script that can build and install the patched kernel module as well as do necessary configuration works for you. Apple Keyboard on ArchWiki also provides a brief steps on how to configure it.

Adding a Second Control key

The command/apple keys on macs are recognized as "Super" or "Windows" shift by default. To make the right command key a ctrl key, save this in ~/.Xmodmap file:

clear control
clear mod4

keycode 37 = Control_L
keycode 134 = Control_R
!### change 134 to 116 if using Ubuntu hardy, not 8.10 or later. ###
add control = Control_L Control_R

add mod4 = Super_L

Then run the command "xmodmap ~/.Xmodmap".

Ubuntu 8.10 (Intrepid Ibex) through 12.04 (Precise Pangolin)

Save the following in a file .Xmodmap in your home directory:

! Swap Alt and Cmd keys.
keycode 37 =    Control_L
keycode 133 =   Alt_L Meta_L
keycode 64 =    Super_L
keycode 108 =   Super_R
keycode 134 =   ISO_Level3_Shift Multi_key
keycode 105 =   Control_R       Multi_key
clear Shift
clear Lock
clear Control
clear Mod1
clear Mod2
clear Mod3
clear Mod4
clear Mod5
add    Shift   = Shift_L Shift_R
add    Lock    = Caps_Lock
add    Control = Control_L Control_R
add    Mod1    = Alt_L 0x007D
!some configurations, for example tha italian layout keyboard, will require this:
!add    Mod1    = Alt_L
!because the "0x007D" will assign the "+*]" key to the unity menu
add    Mod2    = Num_Lock
add    Mod4    = Super_L Super_R
add    Mod5    = Mode_switch ISO_Level3_Shift ISO_Level3_Shift ISO_Level3_Shift

! Configure '=' key on numpad as '='.
keycode 0x7D =  equal

Load the configuration by executing a command similar to the following.

xmodmap ~/.Xmodmap

Note : Gnome will ask you if you want to load this configuration the next time you log in. Sometimes, if you reconfigure many times the same keys, a reboot is required in order to make the configuration work as intended.

Ubuntu 8.04 (Hardy Heron)

This section describe how to change the mapping for Ubuntu 8.04 (Hardy Heron) with kernel >= 2.6.27.

1. Edit or create ~/.Xmodmap file with a content similar to the following.

! Configure F13 as Insert key
! F14 as PrintScr
| F15 as ScrollLock
! F16 as Pause/Break
keycode 182 = Insert
keycode 183  =  Print       Sys_Req
keycode 184  =  Scroll_Lock
keycode 93   =  Pause   Break

! Swap Alt and Command keys
keycode 0x25 =  Control_L
keycode 0x73 =  Alt_L       Meta_L
keycode 0x40 =  Super_L
keycode 0x71 =  Super_R
keycode 0x74 =  ISO_Level3_Shift    Multi_key
keycode 0x75 =  NoSymbol
keycode 0x6D =  Control_R   Multi_key
clear Shift
clear Lock
clear Control
clear Mod1
clear Mod2
clear Mod3
clear Mod4
clear Mod5
add    Shift   = Shift_L Shift_R
add    Lock    = Caps_Lock
add    Control = Control_L Control_R
add    Mod1    = Alt_L 0x007D
add    Mod2    = Num_Lock
add    Mod4    = Super_L Super_R
add    Mod5    = Mode_switch ISO_Level3_Shift ISO_Level3_Shift ISO_Level3_Shift

! Configure '=' key on numpad as '='.
keycode 0x9D =  equal

2. Load the configuration by executing a command similar to the following.

xmodmap ~/.Xmodmap

Note : The configuration should be load on next logon.

Belgian Macintosh Keyboard Layout

Take a look at Macbook_Air#head-5fd0bcf04cc7da0b5241950916bab5d58cdb84da in the Belgian Keyboard section

Disabling non-breaking space

If you work a lot with terminals and for example type "while true; do..." you could easily press SHIFT+Space and you have a non-breaking space which does not work in a terminal. To disable this behaviour you can specify the keycode in ~/.Xmodmap like following:

keycode 65 =space space

Postscript

These issues may also apply for the Bluetooth aluminum Apple Wireless Keyboard.

Numlock on Apple Wireless Keyboard

If the Apple Wirelesss Keyboard stops working after log-in where most keys do not work and some keys on the right side produce numbers, it is because numlock is enabled by default. Numlock can be switched off by pressing fn-F6 twice. The keyboard then works normally again.

To disable numlock by default, go to System -> Preferences -> Keyboard -> Layout -> Layout Options -> Miscellaneous compatibility options -> turn on "Default numeric keypad keys"

This setting takes effect after logging in and does not affect the graphical login screen or local consoles.

Xubuntu 18.04

numlockx is 'ON' by default. Edit the defaults file to fix:

$ editor /etc/default/numlockx 


# Configuration file for numlockx


# State of numlog on start of X session
# Accepts following options:
# auto - turns numlock on unless ran on laptop
# on - turns numlock on
# off - turns numlock off
# keep - does not change numlock state
# toggle - toggles numlock state
NUMLOCK=off


CategoryHardware CategoryXubuntu CategoryAccessories CategoryBluetooth CategoryXwindowSystem

AppleKeyboard (last edited 2018-08-07 13:52:55 by 76-235-14-52)