Difference between revisions of "Xmodmap (简体中文)"

From ArchWiki
Jump to: navigation, search
(Created page with "Category:Input devices Category:X Server de:Xmodmap fr:Xmodmap en:Xmodmap {{Article summary start}} {{Article summary text|A general overview of modifying ...")
 
(fix categories - not an English article)
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Input devices]]
+
[[Category:Input devices (简体中文)]]
[[Category:X Server]]
+
[[Category:X Server (简体中文)]]
 
[[de:Xmodmap]]
 
[[de:Xmodmap]]
[[fr:Xmodmap]]
 
 
[[en:Xmodmap]]
 
[[en:Xmodmap]]
 +
[[fr:Xmodmap]]
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|A general overview of modifying keymaps and pointer mappings with xmodmap.}}
 
{{Article summary text|A general overview of modifying keymaps and pointer mappings with xmodmap.}}
Line 15: Line 15:
 
'''Xmodmap''' is a utility for modifying keymaps and pointer button mappings in [[Xorg]].
 
'''Xmodmap''' is a utility for modifying keymaps and pointer button mappings in [[Xorg]].
  
== Introduction ==  
+
== 介绍 ==  
The Linux kernel generates a code each time a key is pressed on a keyboard. That code is compared to a {{ic|table of keycodes}} defining a figure that is then displayed.
+
在每次按下键盘时, Linux 内核都会生成一个 Code。 Code 同 {{ic|keycodes表}} 比较,然后决定按下的是什么。
  
This process is complicated by [[Xorg]], which starts its own table of keycodes. Each keycode can belong to a {{ic|keysym}}. A keysym is like a function, started by typing a key. Xmodmap allows you to edit these keycode-keysym relations.
+
[[Xorg]] 使用自己的 Keycodes表 来参与这个过程。 每一个 Keycode 属于一个 {{ic|keysym}}。 一个 keysym 就像一个 function 被 Keycode 调用执行。 Xmodmap 允许你编辑 keycode-keysym 之间的关系。
 +
 
 +
== Keymap表 ==
 +
以可被解释的格式打印当前 Keymap表,
  
== Keymap table ==
 
Print the current keymap table formatted into expressions:
 
 
{{hc|$ xmodmap -pke|2=keycode  57 = n N}}
 
{{hc|$ xmodmap -pke|2=keycode  57 = n N}}
  
Each keymap is followed by the {{Ic|keysyms}} it is mapped to. The above example indicates that the keycode {{ic|57}} is mapped to the lowercase ''n'', while the uppercase ''N'' is mapped to keycode {{Ic|57}} and {{Ic|Shift}}.
+
每条 Keymap 之后都跟随要被映射的 {{Ic|keysyms}}。 下面的例子表明 keycode {{ic|57}} 被映射到小写 ''n'', 同时大写 ''N'' 映射于 {{Ic|57}} + {{Ic|Shift}}
 +
 
 +
每个 keysym列 都对应指定的键组合:
  
Each keysym column in the table corresponds to a particular key combination:
 
 
# {{Keypress|Key}}
 
# {{Keypress|Key}}
 
# {{Keypress|Shift+Key}}
 
# {{Keypress|Shift+Key}}
Line 34: Line 36:
 
# {{Keypress|AltGr+Shift+Key}}
 
# {{Keypress|AltGr+Shift+Key}}
  
Not all keysyms have to be set, but if you want to assign a latter keysym without assigning earlier ones set them to {{ic|NoSymbol}}.
+
在 keysym组合 没有被指定时, 使用 {{ic|NoSymbol}} 代替。
  
You can check which keymap corresponds to a key on your keyboard with [[Extra Keyboard Keys#Using xev|xev]].
+
使用 [[Extra Keyboard Keys#Using xev|xev]] 来查看每个键对应的 keymap.
  
{{tip|There are predefined descriptive keycodes that make mapping additional keys easier (e.g. {{ic|XF86AudioMute}}, {{ic|XF86Mail}}). Those keycodes can be found in: {{ic|/usr/include/X11/XF86keysym.h}}}}
+
{{tip| There are predefined descriptive keycodes that make mapping additional keys easier (e.g. {{ic|XF86AudioMute}}, {{ic|XF86Mail}}). Those keycodes can be found in: {{ic|/usr/include/X11/XF86keysym.h}}}}
  
 
== Custom table ==
 
== Custom table ==

Revision as of 18:37, 17 May 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Xmodmap is a utility for modifying keymaps and pointer button mappings in Xorg.

介绍

在每次按下键盘时, Linux 内核都会生成一个 Code。 Code 同 keycodes表 比较,然后决定按下的是什么。

Xorg 使用自己的 Keycodes表 来参与这个过程。 每一个 Keycode 属于一个 keysym。 一个 keysym 就像一个 function 被 Keycode 调用执行。 Xmodmap 允许你编辑 keycode-keysym 之间的关系。

Keymap表

以可被解释的格式打印当前 Keymap表,

$ xmodmap -pke
keycode  57 = n N

每条 Keymap 之后都跟随要被映射的 keysyms。 下面的例子表明 keycode 57 被映射到小写 n, 同时大写 N 映射于 57 + Shift

每个 keysym列 都对应指定的键组合:

  1. Template:Keypress
  2. Template:Keypress
  3. Template:Keypress
  4. Template:Keypress
  5. Template:Keypress
  6. Template:Keypress

在 keysym组合 没有被指定时, 使用 NoSymbol 代替。

使用 xev 来查看每个键对应的 keymap.

Tip: There are predefined descriptive keycodes that make mapping additional keys easier (e.g. XF86AudioMute, XF86Mail). Those keycodes can be found in: /usr/include/X11/XF86keysym.h

Custom table

You can create your own map and store it in your home directory (i.e. ~/.Xmodmap). Print the current keymap table into a configuration file:

xmodmap -pke > ~/.Xmodmap

Make the desired changes to ~/.Xmodmap and then test the new configuration with:

xmodmap ~/.Xmodmap

To activate your custom table when starting Xorg add the following:

~/.xinitrc
if [ -f $HOME/.Xmodmap ]; then
    /usr/bin/xmodmap $HOME/.Xmodmap
fi

Alternatively, edit the global startup script /etc/X11/xinit/xinitrc.

Test changes

You can also make temporary changes for the current session. For example:

xmodmap -e "keycode  46 = l L l L lstroke Lstroke lstroke"
xmodmap -e "keysym a = e E"

Special keys/signals

You can also also edit the keys: Template:Keypress, Template:Keypress, Template:Keypress and Template:Keypress (there always exists a left and a right one (Alt_R=AltGr))

At first you have to delete/clear the signals that should be edited. In the beginning of your ~/.Xmodmap:

!clear Shift
!clear Lock
clear Control
!clear Mod1
!clear Mod2
!clear Mod3
clear Mod4
!clear Mod5
keycode   8 =
...

Remember, ! is a comment so only Template:Keypress and Template:Keypress (Standard: Super_L Super_R) get cleared.

Write the new signals at the end of ~/.Xmodmap

keycode 255 =
!add Shift   = Shift_L Shift_R
!add Lock    = Caps_Lock
add Control = Super_L Super_R
!add Mod1    = Alt_L Alt_R
!add Mod2    = Mode_switch
!add Mod3    =
add Mod4    = Control_L Control_R
!add Mod5    =

The Template:Keypress keys have now been exchanged with the Template:Keypress keys.

Reverse Scrolling

The natural scrolling feature available in OS X Lion can be mimicked with xmodmap. Since the synaptics driver uses the buttons 4/5/6/7 for up/down/left/right scrolling, you simply need to swap the order of how the buttons are declared in ~/.Xmodmap.

Open ~/.Xmodmap and append the following line to the file:

pointer = 1 2 3 5 4 7 6 8 9 10 11 12

Note how the 4 and 5 have been reversed.

Then update xmodmap:

xmodmap ~/.Xmodmap

To return to regular scrolling simply reverse the order of the 4 and 5 or delete the line altogether. For more information check Peter Hutterer's post, Natural scrolling in the synaptics driver, or the Reverse scrolling direction ala Mac OS X Lion? forum thread.

Additional resources