Change keys for Apple keyboard on Linux

I use an Apple keyboard at my workstation. However, I was bothered by the layout of certain keys under Linux. So I did a little research and set out to change this myself.

The first thing we need to do is install evtest

(Debian/Ubuntu)

sudo apt install evtest

(Fedora/Rhel)

sudo dnf install evtest

With this we can display different values of pressed keys in the command line.

After the installation we start evtest simply in the command line with

evtest

Now you look for the matching event number to your keyboard

Select the device event number:

and type the number and press Enter

Now it’s time. Press the key on your keyboard you want to change. In this example I decide to use the Enter key.

Event: time 1668908629.343883, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70028

Event: time 1668908629.343883, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0

At the end of the first line we are interested in the number after value.

Create a new file at

sudo nano /etc/udev/hwdb.d/70-keyboard.hwdb

and make your change there.

This is my example file how I set it up for me

  evdev:name:Magic Keyboard:*         # name, the same as in event number
      # KEYBOARD_KEY_value=function   # function, 2nd line of Event
        KEYBOARD_KEY_C00B8=delete     # map EJECT to Delete
        KEYBOARD_KEY_700E0=leftmeta   # map ctrl to leftmeta
        KEYBOARD_KEY_700E2=leftalt    # map alt to leftalt
        KEYBOARD_KEY_700E3=leftctrl   # map cmd to leftctrl

Update the Hardware Database

sudo udevadm hwdb –update

Make it directly avaiable (XX stands for your right event number)

sudo udevadm trigger /dev/input/eventXX

That’s it.

Christopher Horn
Christopher Horn
Student of Computer Science

My interests include system administration, server security and server automation.