Tuesday, October 8, 2013

[SOLVED] Add custom characters to keyboard layout in Ubuntu

After a lot of attempts, which were not definitive, I finally managed to add some custom characters to my keyboard layout which were not included, avoiding to switch form one layout to another for just some characters.

Here I use as example how I added some German characters (ä,ö,ü,...) on my Italian layout.

  • temporally change your layout with a similar one:
    Menu -> Keyboard Layout ->  Layout -> + -> chose a different one from your current (I chose English UK)
  • open a terminal (CTRL+ALT+T)
  • type cd /usr/share/X11/xkb/symbols/
  • type ls to see all the layouts, and identify which one your was (in my case it, in the following steps substitute it with your layout)
  • make a backup copy: sudo cp it it.backup
  • open the file: sudo gedit it &
  • identify the key you want to edit: if for example you want to add the "ä" as third option on the "A" key, search for the lines which contain "a" and "A" at the beginning; in this case it is:
        key <AC01> { [a, A, aring, Aring] };
  • substitute the third element ("aring" or whatever you have) with "adiaeresis" and eventually the fourth with "Adiaeresis" in order to get an "Ä"; this in ALL lines (there can be more of them for different layout settings) where that specific key appears. 'A' key lines should then look like
        key <AC01> { [a, A, adiaeresis, Adiaeresis] };
  • add other desired characters as well; if you don't know their code (e.g. "adiaeresis"), just look for them in that language's layout
  • save & close
  • in the Terminal type sudo dpkg-reconfigure keyboard-configuration and follow the on-screen instructions
  • then type sudo dpkg-reconfigure console-setup and follow the on-screen instructions
  • close all programs and reboot: sudo reboot
  • after logging in go again to Menu -> Keyboard Layout ->  Layout, remove the previously set layout and add your default one; now, following the above example, you should be able to get an "ä" by AltGr+A and an "Ä" by SHIFT+AltGr+A