I have a Keychron K2 mechanical keyboard and the keys on the righthand side of the keyboard look like this:

enter image description here

I would like to swap them to a more standard layout, so that, from top to bottom, I would have Light Toggle, Home, Page Up, Page Down, and End.

I used xev to retrieve the key codes and wrote a small script that uses xmodmap to swap them to my liking:


xmodmap -e "keycode 110 = Next" && xmodmap -e "keycode 112 = Home" && xmodmap -e "keycode 117 = Prior"

This script is executed on start up and works exactly as expected.

The problem is this keyboard is both wired and Bluetooth. When I switch between wired mode to Bluetooth mode or vice-versa, the keys go back to their default position and I need to manually run my script above one more time. xev shows to me that in both cases the key codes are the same. Is there a better way of tackling this so that these keys are swapped regardless of the keyboard mode I use?

  • Alternatively, is there a better way of accomplishing this? On Windows (I'm dual booting), I managed to hard code the changes directly in the registry, so that every keyboard will have those swapped. Is there an equivalent for Linux? Dec 12, 2020 at 22:49

1 Answer 1


Unfortunately, in Linux Mint (and Ubuntu derivates) xmodmap resets whenever a keyboard is plugged/unplugged or when a new keyboard is detected. In the case of keyboards with dual mode like mine, the system understands that these are two separate keyboards and will reset xmodmap at that point.

The solution to this is to edit the file pc in /usr/share/X11/xkb/symbols/ using:

$ sudo nano /usr/share/X11/xkb/symbols/pc

Then change lines 77, 78, and 81 from...:

    key <HOME> {    [  Home         ]   };
    key <PGUP> {    [  Prior        ]   };
    key <PGDN> {    [  Next         ]   };

... to:

    key <HOME> {    [  Next         ]   };
    key <PGUP> {    [  Home         ]   };
    key <PGDN> {    [  Prior        ]   };

This will hardcode change those keys for all keyboards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.