How to use an Apple keyboard with Linux
Contents
Introduction

In this article, I try to describe how to use an Apple keyboard with X.Org on Linux including the correct layout and special keys.
Apple keyboards have a special layout, with up to four layers of characters. This requires some special settings to use them with all features.
They also feature several special keys. These include volume up, volume down, mute and eject. On portable Apple computers, there are also keys for the display’s brightness and more.
Terminology
If you come from a Linux/x86 background, you should note the different names for the keys.
- Shift
- Normal shift key.
- Alt
- Called “alt” on keyboard, used for special characters, also called “option” key.
- Command
- “Apple” key, equivalent to “Alt” on Linux/x86, also called “command” key.
X.Org
I used to have a set of patches linked from here, but after having too much trouble with upstream’s layout definitions, I decided to create my own one using xmodmap and load it when starting the window manager. Below you find a description on how to do this.
I’m using the Swiss German keyboard layout, but you can apply the following to any other keyboard layout. It has been several months since I did this, so the following is just a write down of what I remember.
The starting point for the new way was the output of “xmodmap -pke” on a machine that had my old customized keyboard layout. You can do this also with another layout like US English. That layout then needed all modifications to be applied. As an example, the modifier keys had to be defined. You can find the available commands in “man 1 xmodmap”.
Once you created your new layout, you can test it:
setxkbmap -verbose 10 -model macintosh -layout ch && \ xmodmap ~/.xmodmap
The setxkbmap command is used to set a default keyboard layout. It should be the same as configured in xorg.conf.
Once it works, you can configure your window manager to execute these commands on startup. For Fluxbox, this can be done in ~/.fluxbox/startup.
If you want a real example, download my customized de_CH layout for Apple keyboards.
Mapping commands
The descriptions below are only for Fluxbox. If someone provides me with others, I’ll add them to this article.
Fluxbox
The following lines can be added to ~/.fluxbox/keys:
# Lower volume by 5% None XF86AudioLowerVolume :ExecCommand amixer sset PCM 5- unmute # Raise volume by 5% None XF86AudioRaiseVolume :ExecCommand amixer sset PCM 5+ unmute # Mute audio (for sound cards without mute support) None XF86AudioMute :ExecCommand amixer sset PCM 0 # Mute audio (for sound cards with mute support) # None XF86AudioMute :ExecCommand amixer sset PCM toggle
# Eject key, requires eject 2.1.x None XF86Eject :ExecCommand eject -T
# Play previous title Mod1 XF86AudioLowerVolume :ExecCommand audacious --rew # Play next title Mod1 XF86AudioRaiseVolume :ExecCommand audacious --fwd # Play/pause Mod1 XF86AudioMute :ExecCommand audacious --play-pause
Make sure to reload the Fluxbox configuration after configuring the keys. There should be a menu entry for it.