remove Lock = Caps_Lock
remove Control = Control_R
keysym Control_R = Caps_Lock
keysym Caps_Lock = Control_R
add Lock = Caps_Lock
add Control = Control_R
keysym Shift_L = Escape
http://www.programgo.com/article/49642670420/
Based on the concept of "it is better to teach a man to fish than to give a man a fish", this article will give the conclusion and the method to get the conclusion.
Under the influence of Linux philosophy, Linux programmers often have some special ideas to improve work efficiency. Such as writing repetitive mechanical labor into a script, or the content of this article - changing key positions.
HHKB is the preferred keyboard for vimer under Linux. Regardless of the feel of capacitive keyboard, its key position is designed for vim: pull ESC, BackSpace, and put Ctrl to the left of A, and vimer needs to press Ctrl all day long, so that The design will greatly reduce the fatigue of the little finger. But the price of this cool keyboard is as high as 2000RMB, and it is easy to be said by colleagues to "install B".
Before buying HHKB, I tried to use KBC POKER to realize the key position of HHKB; after buying HHKB, wow, this set of configuration is even more essential, because I can no longer use ordinary keyboards.
Next, I will talk about the specific implementation. My OS is Ubuntu 10.04 LTS, which is implemented through xmodmap, which is valid for the entire X desktop.
1. How to implement
First look at the current key positions of the system (and the representation of each key):
# xmodmap -pke > /tmp/map
Edit the /tmp/map file and find the following 4 lines:
#----------------------------------------------------------------------
keycode 9 = Escape NoSymbol Escape
keycode 37 = Control_L NoSymbol Control_L
keycode 49 = grave asciitilde grave asciitilde
keycode 66 = Caps_Lock NoSymbol Caps_Lock
#----------------------------------------------------------------------
It is the corresponding ESC, left CTRL, accent and CAPS_LOCK keys.
My purpose is to swap ESC and accent, CAPS_LOCK is mapped to left CTRL, modify
~/.xmodmaprc
#----------------------------------------------------------------------
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
!remove Control = Control_L
!keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
!add Lock = Caps_Lock
add Control = Control_L
!
! keycode 9 = grave asciitilde grave asciitilde
! keycode 49 = Escape NoSymbol Escape
keysym Escape = grave asciitilde grave asciitilde
keysym grave = Escape
#----------------------------------------------------------------------
Then restart xserver to log in to the current user.
When the gnome desktop starts, it will detect the configuration files matching ~/.xmodmap*. If a new configuration file is found, a dialog box will automatically pop up to select which configuration files to load.
Then, you're done!
The usage of the specific script can be man xmodmap, but it should not be too difficult to draw the scoop according to the gourd.
2. If you have moved Ubuntu's keyboard options, there are certain key mapping options
If step 1 is successful, you may not need to read any further. However, if it doesn't work, it may be the following reasons.
But there are some keymap options in Ubuntu's keyboard options (for example, System-Preferences-Keyboard-Layout-Options-"Ctrl Key Position" select "Make CapsLock an additional Ctrl"), and applying these options will be faster than xmodmap is later, causing them to override the settings of left CTRL and CAPS_LOCK.
Moreover, what is even more hateful is that if you have set the keyboard preference "Ctrl Key Position" in desktop/gnome/peripherals/keyboard (system-preferences-keyboard), there is no way to cancel this setting through the graphical interface. Even if it is set to "default", the system will reset the keys when starting the gnome desktop, and then overwrite my configuration in .xmodmaprc. This option needs to be cleared at this time.
a) Modify
~/.gconf/desktop/gnome/peripherals/keyboard/kbd/%gconf.xml
delete the following nodes
#----------------------------------------------------------------------
<li type="string">
<stringvalue>ctrl ctrl:swapcaps</stringvalue>
</li>
#----------------------------------------------------------------------
b) modify
~/.gconfd/saved_state
Delete all lines with "keyboard".
c) Write .xmodmaprc, then restart xserver (Ctrl+Alt+Backspace, if this shortcut is enabled), which will automatically write the configuration to ~/.gconfd/saved_state. Then it works every time you boot up.
3. What if .xmodmaprc is not loaded into the configuration
When you accidentally disable .xmodmaprc, or modify .xmodmaprc but nothing happens, you can try:
Revise
~/.gconf/desktop/gnome/peripherals/keyboard/general/%gconf.xml
delete the following nodes
#----------------------------------------------------------------------
<entry name="known_file_list" mtime="1315277419" type="list" ltype="string">
<li type="string">
<stringvalue>.xmodmaprc</stringvalue>
</li>
<li type="string">
<stringvalue>xmodmaprc</stringvalue>
</li>
</entry>
#----------------------------------------------------------------------
The next time you boot up, you can choose whether to load the configuration again.
The picture below shows HHKB (Delete is actually Backspace, and the block is actually Alt) and KBC POKER
The final configuration is like this
remove Lock = Caps_Lock
remove Control = Control_R
keysym Control_R = Caps_Lock
keysym Caps_Lock = Control_R
add Lock = Caps_Lock
add Control = Control_R
keysym Escape = grave asciitilde grave asciitilde
keysym grave = Escape asciitilde
The esc key is changed to the `~ key, and the original `~ key is changed to the tab~ key