Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Apple Magic Keyboard mapping for Linux Mint

Map an Apple Magic Keyboard to a Linux machine

Configured for a Mac-like experience

Apple Magic Keyboard 2: Model A1644 (same as MLA22LL/A ?)

Mapping for Linux Mint 18 Cinnamon 64-bit

xmodmap source

Map Ctrl to command (currently Win or Super):

Go to System Settings > Keyboard > Layouts > English (US) > Options... > Ctrl key position > check:
* Swap Left Win key with Left Ctrl key
* Swap Right Win key with Right Ctrl key

There are a lot of different variations for the modifier keys in these settings. This is just my preference and what I thought worked best for me.

Get the keycodes for each key:

$ xmodmap -pke

You can run

$ xev

for an interactive experience by pressing each key and seeing the response. This is more detailed but much longer, as you have to press each key to get the keycode.

Desired keys to map:

110 Home    => 67 F1
115 End	    => 68 F2
112 Prior   => 73 F7
118 Insert  => 74 F8
117 Next    => 75 F9
119 Delete  => 169 Eject

A personal preference of mine is to use this new mapping, but also keep the original keys by allowing it through the use of:


for example, Shift+F1, will output F1, but just F1 will output Home...

Map Home to F1:

$ xmodmap -e "keycode 67 = Home F1"

Map End to F2:

$ xmodmap -e "keycode 68 = End F2"

Map PgUp to F7:

$ xmodmap -e "keycode 73 = Prior F7"

Map Insert to F8:

$ xmodmap -e "keycode 74 = Insert F8"

Map PgDn to F9:

$ xmodmap -e "keycode 75 = Next F9"

Map Delete to Eject:

$ xmodmap -e "keycode 169 = Delete"

I have no use for an eject key, thus I will not keep for use with Shift

Your custom keys should work immdiately.

Note your changes in case you have to revert your custom mapping.

For example, reverse Home back to F1:

$ xmodmap -e "keycode 110 = Home"
$ xmodmap -e "keycode 67 = F1"

or revert each custom key:

$ xmodmap ~/xmodmap_original

Save your custom key map in your home directory:

$ xmodmap -pke > ~/.Xmodmap

Build your custom key map (for each login session):

$ xmodmap ~/.Xmodmap

Automatically build your map on boot

If you find your custom key mapping is reverting after you login or reboot, then load it up for each session:

Create a new file called '.xinitrc' in your home directory and copy this in it:

if [ -s ~/.Xmodmap ]; then
    xmodmap ~/.Xmodmap

thanks to for the build on boot tip.

P.S. I also mapped Scale to F3 and expo to F4 by simply adding a shortcut via settings:

Go to System Settings > Keyboard > Shortcuts > General > 

Toggle Scale > F3

Toggle Expo > F4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.