I'm fairly new to Ubuntu (and Linux) and one of the first things I wanted to do was remap certain keys due to some keys that are located in "unwanted" positions. I thought that wasn't going to be so hard, but after reading through documentation and be redirected many times I ended up logging in as root and modifying the evdev file in /usr/share/X11/xkb and changing the keycodes.

Apparently, you can configure your default keyboard on startup, but due to the amount of time that it has taken me to get some understanding towards this whole system, I haven't tried it as of yet. It seems like that would actually achieve to configure the default keyboard it in the "right" way.

At this moment I would like to know if it is possible to add another modifier key (eg. Ctrl) that is bound to another key (eg. <CTL2>), but already having 2 modifier keys used (in other words, I have used 2 Ctrl keys, but want an additional one that behaves as either a left or right Ctrl key).

System Info

Ubuntu 17.04 (kernel information: Linux 4.10.0-37-generic #41-Ubuntu SMP Fri Oct 6 20:20:37 UTC 2017)
X Keyboard Extension (XKB) configuration data v.2.19
  • 1
    in XKB, <FOO> is a keycode, which you probably shouldn't change. the symbols for the typical control keys are Control_L and Control_R. see askubuntu.com/a/896297/669043 and the resources linked there. – quixotic Oct 25 '17 at 20:45

Unfortunately, and AFAIK, there is no really good documentation on how to configure XKB. But doesn't the answer you linked to apply to your specific question?

You can view the available options for tweaking XKB by running this command:

man xkeyboard-config

from terminal and scroll down. That's what I did before answering the other question. :)

  • I didn't even even know this man page existed. I've mainly been looking at setxkbmap and xkbcomp. The main thing I can't really understand is how the behaviors are added to the keys. For example, if I add a custom key in pc file in usr/share/X11/xkb/symbols and I add the same 'behavior' (eg. Shift_R) then it overrides the previous key, making it seem like they're mutually exclusive. It seems then that I need to actually read the source code to know if what I want is even possible. – pdvries Oct 11 '17 at 17:20

I did found a solution to my problem. I'm currently not aware of any other solutions, so I do like to share it here.

The reason for start changing the evdev file in usr/share/X11/xkb/keycodes started out of the frustration of not understanding why changes didn't seem to occur when adding another keyboard layout during the startup process (using different configuration files). There's a number of posts out there that speak about changing the keycodes and its from that angle that I eventually decided to change them in evdev.

To make this work:

  1. Add the modifier key (eg. <SHF2>) to your evdev-file (or if you have built a custom keyboard layout you need to change it in there).
  2. Then, based upon the modifier key you need to add it to the modifier_map in the pc-file in usr/share/X11/xkb/symbols. Now, from what I understand is that the entry needs to be to opposite of the last added key. So, by default, the latter key is either a right Shift- or right Control key. Therefore, the added modifier needs to be a left Shift- or left Control key, which looks like this:

    key <SHF2> { [ Shift_L ] };

    modifier_map Shift { Shift_L, Shift_R, <SHF2> };

  3. Reboot. (maybe this step is not needed if you know how to re-configure these changes without rebooting)

NOTE: I only did the Shift and Control modifier here. If you want to add another Alt key (based upon the behavior of the left Alt key) then you need to change the altwin-file in usr/share/X11/xkb/symbols and add the line: key <ALT2> { [ Alt_L, Meta_L ] }; (where <ALT2> is the name you specified in evdev or otherwise configured in your custom keyboard layout-file) to this file and "re-configure"/reboot.

  • 1
    Thank you so much! In my case I bought a European laptop that splits left Shift on 2 buttons. I wanted to make this 2nd button to be Shift also. It was LSGT < key. For me it was sufficient just to add the line: key <LSGT> { [ Shift_L ] }; in /usr/share/X11/xkb/symbols/pc. Ubuntu 18.04 – vogdb Aug 9 '20 at 14:44

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.