This article was reproduced from: http://hessian.cn/p/144.html
Go Keyboard mapping in Linux
Original address: http://www.linuxidc.com/Linux/2011-04/35197.htm
For English, the alphabet keys on the keyboard correspond directly to the letters in the English alphabet, but for non-English languages, the situation is not the same. For example, the "ß" letter in German does not have a direct key and it corresponds, so that Linux provides "keyboard mapping" or "keyboard translation", using keyboard mapping to convert certain keys to special keys.
As mentioned earlier, the X window processes the input and output ports of the keyboard directly, so different keyboard mapping methods are used under the Linux Virtual Console and under the X window. On the Linux Virtual Console, you can use the Loadkeys command to map special keys to special characters, while in X Window you must use the XMODMAP command to complete the keyboard mapping. These commands are translated according to the rules in the Character Map file (text file). When X Window starts, it will refer to the character Map in Linux text mode, so some consistent key mappings can be obtained.
The Character Map file is saved in the/usr/lib/kbd/keytables directory, and Defkeymap.map is the default character mapping table file. Using commands:
$ loadkeys fr. Map
Can be loaded into the character mapping table specified by Fr.map. At this point, press "." The ":" is displayed. Command
$ loadkeys–d
The default character mapping table can be mounted. For non-default keyboard mappings, a special mapping table can be loaded in shell scripts at startup.
For x Window, it has a two-step process for handling the keyboard as follows:
1. X Server First converts the key code to the key symbol name (KEYSYM). The file/usr/include/x11/keysymdef.h contains all the symbol names. X Server can differentiate between modifier keys, because keysymdef.h distinguishes between two different keys, for example, "a" and "a", respectively, with "Ks_a" and "ks_a" defined.
2. X Server translates the key symbol to an ASCII string. For most keys, the string contains only one character, and for special keys, such as a function key, it contains more than one character. For example, the default ASCII string corresponding to the F5 key is "5~".
Use the Xmodmap tool to modify the correspondence between keyboard and key symbol names. For example, the key code for "A" in X window is 30, while the key code for "Q" is 16. If you set up file Maptest:
= Q
Running in Xterm
$ xmodmap Maptest
After that, you will find that the "A" key and the "Q" key have been exchanged.
The Maptest file above is actually a simple X Window mapping file. However, it is important to note that the KeyCode and Linux kernels in the file define the key values differently, in general, the key code in X Window is 8 larger than the kernel key value. The Showkey command allows you to see the definition of key values in the kernel. For example, after running Showkey and pressing "A" and "Q" before and after, the output of the program is:
$ showkeykb mode was RAW
The program gives the kernel key values of "A" and "Q".
In the Xf86config file, the Keyboard segment is used to specify keyboard parameters, which generally do not require special settings:
5EndSection
Keyboard mapping "Go" in Linux