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

From ArchWiki
Jump to: navigation, search
m (Keymap表: fixed link)
m (MAC OS X的自然滚动)
 
(13 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
[[Category:Input devices (简体中文)]]
 
[[Category:Input devices (简体中文)]]
[[Category:X Server (简体中文)]]
+
[[Category:X server (简体中文)]]
 
[[de:Xmodmap]]
 
[[de:Xmodmap]]
 
[[en:Xmodmap]]
 
[[en:Xmodmap]]
 
[[fr:Xmodmap]]
 
[[fr:Xmodmap]]
{{Article summary start}}
+
[[ja:Xmodmap]]
{{Article summary text|A general overview of modifying keymaps and pointer mappings with xmodmap.}}
+
[[ru:Xmodmap]]
{{Article summary heading|Related}}
+
{{Related articles start (简体中文)}}
{{Article summary wiki|Xorg}}
+
{{Related|Xorg}}
{{Article summary wiki|Extra Keyboard Keys}}
+
{{Related|Extra keyboard keys}}
{{Article summary wiki|Extra Keyboard Keys in Xorg}}
+
{{Related|Extra keyboard keys in Xorg}}
{{Article summary wiki|Extra Keyboard Keys in Console}}
+
{{Related|Extra keyboard keys in console}}
{{Article summary end}}
+
{{Related articles end}}
 
+
{{Translateme (简体中文)}}
 
'''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]].
  
== 介绍 ==  
+
== 介绍 ==
 
在每次按下键盘时, Linux 内核都会生成一个 Code。 Code 同 {{ic|keycodes表}} 比较,然后决定按下的是什么。
 
在每次按下键盘时, Linux 内核都会生成一个 Code。 Code 同 {{ic|keycodes表}} 比较,然后决定按下的是什么。
  
Line 38: Line 38:
 
在 keysym组合 没有被指定时, 使用 {{ic|NoSymbol}} 代替。
 
在 keysym组合 没有被指定时, 使用 {{ic|NoSymbol}} 代替。
  
使用 [[Extra Keyboard Keys#In Xorg|xev]] 来查看每个键对应的 keymap.
+
使用 [[Extra keyboard keys#In Xorg|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| 有一些预定义的keycodes被映射成附加的快捷键 (e.g. {{ic|XF86AudioMute}}, {{ic|XF86Mail}}). 那些keycodes能在这个文件找到: {{ic|/usr/include/X11/XF86keysym.h}}}}
  
== Custom table ==
+
== 自定义映射表 ==
You can create your own map and store it in your home directory (i.e. {{ic|~/.Xmodmap}}). Print the current keymap table into a configuration file:
+
你可以创建自己的映射表并且把它储存在你的{{ic|home}}目录下(i.e. {{ic|~/.Xmodmap}}). 输出当前键盘映射表到一个配置文件中:
 
  xmodmap -pke > ~/.Xmodmap
 
  xmodmap -pke > ~/.Xmodmap
  
Make the desired changes to {{ic|~/.Xmodmap}} and then test the new configuration with:
+
{{ic|~/.Xmodmap}} 文件中做好想要的修改 然后测试新的配置文件:
 
  xmodmap ~/.Xmodmap
 
  xmodmap ~/.Xmodmap
  
To activate your custom table when starting Xorg add the following:
+
要在启动Xorg时激活你自己的映射表,请添加下面的文件和内容:
 +
 
 
{{hc|~/.xinitrc|
 
{{hc|~/.xinitrc|
 
if [ -f $HOME/.Xmodmap ]; then
 
if [ -f $HOME/.Xmodmap ]; then
Line 55: Line 56:
 
fi}}
 
fi}}
  
Alternatively, edit the global startup script {{ic|/etc/X11/xinit/xinitrc}}.
+
或者你也可以编辑全局启动脚本 {{ic|/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 "keycode  46 = l L l L lstroke Lstroke lstroke"
 
  xmodmap -e "keysym a = e E"
 
  xmodmap -e "keysym a = e E"
  
== Special keys/signals ==
+
== 特殊的按键 ==
  
You can also also edit the keys: {{ic|Shift}}, {{ic|Ctrl}}, {{ic|Alt}} and {{ic|Super}} (there always exists a left and a right one (Alt_R=AltGr))
+
你也可以编辑这些特殊的按键: {{ic|Shift}}, {{ic|Ctrl}}, {{ic|Alt}} and {{ic|Super}} (这里存在左右之分 (Alt_R=AltGr))
  
At first you have to delete/clear the signals that should be edited. In the beginning of your {{ic|~/.Xmodmap}}:
+
首先你必须delete/clear你想要编辑的按键在{{ic|~/.Xmodmap}}这个文件的开头:
 
  !clear Shift
 
  !clear Shift
 
  !clear Lock
 
  !clear Lock
Line 77: Line 78:
 
  keycode  8 =
 
  keycode  8 =
 
  ...
 
  ...
Remember, {{ic|!}} is a comment so only {{ic|Control}} and {{ic|Mod4}} (Standard: Super_L Super_R) get cleared.
+
记住, {{ic|!}} 是一个注释符号 所以只有 {{ic|Control}} {{ic|Mod4}} (Standard: Super_L Super_R) 被clear了.
  
Write the new signals at the end of {{ic|~/.Xmodmap}}
+
把你的修改写到 {{ic|~/.Xmodmap}} 文件末尾
 
  keycode 255 =
 
  keycode 255 =
 
  !add Shift  = Shift_L Shift_R
 
  !add Shift  = Shift_L Shift_R
Line 89: Line 90:
 
  add Mod4    = Control_L Control_R
 
  add Mod4    = Control_L Control_R
 
  !add Mod5    =
 
  !add Mod5    =
The {{ic|Super}} keys have now been exchanged with the {{ic|Ctrl}} keys.
+
现在 {{ic|Super}} 键 和 {{ic|Ctrl}} 键被交换了.
  
== Reverse Scrolling ==
+
附加一个将{{ic|CapsLock}}映射成{{ic|Control}}, {{ic|Shift+CapsLock}}映射成{{ic|CapsLock}}的例子:
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 {{ic|~/.Xmodmap}}.
+
{{ic|~/.Xmodmap}}
 +
clear lock
 +
clear control
 +
add control = Caps_Lock Control_L Control_R
 +
keycode 66 = Control_L Caps_Lock NoSymbol NoSymbol
  
Open {{ic|~/.Xmodmap}} and append the following line to the file:
+
== MAC OS X的自然滚动 ==
pointer = 1 2 3 5 4 7 6 8 9 10 11 12
+
你能用xmodmap去模仿OS X上的自然滚动(反向滚动) 因为synaptics驱动使用按键 4/5/6/7 作为 up/down/left/right 滚动, 你只需要交换按钮的命令,它的描述在这个文件 {{ic|~/.Xmodmap}} .
Note how the 4 and 5 have been reversed.
+
  
Then update xmodmap:
+
打开 {{ic|~/.Xmodmap}} 文件,然后把下面这行添加到文件里面:
 +
pointer = 1 2 3 5 4 7 6 8 9 10 11 12
 +
现在4和5互换了
 +
然后更新xmodmap的设置:
 
  xmodmap ~/.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, [http://who-t.blogspot.com/2011/09/natural-scrolling-in-synaptics-driver.html Natural scrolling in the synaptics driver], or the [https://bbs.archlinux.org/viewtopic.php?id=126258 Reverse scrolling direction ala Mac OS X Lion?] forum thread.
+
恢复只需要交换4和5或者完全删除那行. 获取更多的信息请查看Peter Hutterer的帖子, [http://who-t.blogspot.com/2011/09/natural-scrolling-in-synaptics-driver.html Natural scrolling in the synaptics driver], 或者 [https://bbs.archlinux.org/viewtopic.php?id=126258 Reverse scrolling direction ala Mac OS X Lion?] 论坛帖子
  
 
== Additional resources ==
 
== Additional resources ==
Line 107: Line 114:
 
*[http://cweiske.de/howto/xmodmap/allinone.html Multimediakeys with .Xmodmap HOWTO] by Christian Weiske
 
*[http://cweiske.de/howto/xmodmap/allinone.html Multimediakeys with .Xmodmap HOWTO] by Christian Weiske
 
*[http://dev-loki.blogspot.com/2006/04/mapping-unsupported-keys-with-xmodmap.html Mapping unsupported keys with xmodmap] by Pascal Bleser
 
*[http://dev-loki.blogspot.com/2006/04/mapping-unsupported-keys-with-xmodmap.html Mapping unsupported keys with xmodmap] by Pascal Bleser
*[http://en.gentoo-wiki.com/wiki/Multimedia_Keys Multimedia Keys article] on the [http://en.gentoo-wiki.com/ Gentoo Wiki]
 
 
*[http://keytouch.sourceforge.net/howto_keyboard/node4.html How to retrieve scancodes] by Marvin Raaijmakers
 
*[http://keytouch.sourceforge.net/howto_keyboard/node4.html How to retrieve scancodes] by Marvin Raaijmakers
 
*[http://wiki.linuxquestions.org/wiki/List_of_Keysyms_Recognised_by_Xmodmap List of Keysyms Recognised by Xmodmap] on [http://linuxquestions.org LinuxQuestions]
 
*[http://wiki.linuxquestions.org/wiki/List_of_Keysyms_Recognised_by_Xmodmap List of Keysyms Recognised by Xmodmap] on [http://linuxquestions.org LinuxQuestions]

Latest revision as of 03:29, 25 January 2017

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

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. Key
  2. Shift+Key
  3. mode_switch+Key
  4. mode_switch+Shift+Key
  5. AltGr+Key
  6. AltGr+Shift+Key

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

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

Tip: 有一些预定义的keycodes被映射成附加的快捷键 (e.g. XF86AudioMute, XF86Mail). 那些keycodes能在这个文件找到: /usr/include/X11/XF86keysym.h

自定义映射表

你可以创建自己的映射表并且把它储存在你的home目录下(i.e. ~/.Xmodmap). 输出当前键盘映射表到一个配置文件中:

xmodmap -pke > ~/.Xmodmap

~/.Xmodmap 文件中做好想要的修改 然后测试新的配置文件:

xmodmap ~/.Xmodmap

要在启动Xorg时激活你自己的映射表,请添加下面的文件和内容:

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

或者你也可以编辑全局启动脚本 /etc/X11/xinit/xinitrc.

测试你的修改

你也可以在当前会话做临时的修改。 一个例子:

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

特殊的按键

你也可以编辑这些特殊的按键: Shift, Ctrl, Alt and Super (这里存在左右之分 (Alt_R=AltGr))

首先你必须delete/clear你想要编辑的按键在~/.Xmodmap这个文件的开头:

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

记住, ! 是一个注释符号 所以只有 ControlMod4 (Standard: Super_L Super_R) 被clear了.

把你的修改写到 ~/.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    =

现在 Super 键 和 Ctrl 键被交换了.

附加一个将CapsLock映射成Control, Shift+CapsLock映射成CapsLock的例子: ~/.Xmodmap

clear lock
clear control
add control = Caps_Lock Control_L Control_R
keycode 66 = Control_L Caps_Lock NoSymbol NoSymbol

MAC OS X的自然滚动

你能用xmodmap去模仿OS X上的自然滚动(反向滚动) 因为synaptics驱动使用按键 4/5/6/7 作为 up/down/left/right 滚动, 你只需要交换按钮的命令,它的描述在这个文件 ~/.Xmodmap 里.

打开 ~/.Xmodmap 文件,然后把下面这行添加到文件里面:

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

现在4和5互换了 然后更新xmodmap的设置:

xmodmap ~/.Xmodmap

恢复只需要交换4和5或者完全删除那行. 获取更多的信息请查看Peter Hutterer的帖子, Natural scrolling in the synaptics driver, 或者 Reverse scrolling direction ala Mac OS X Lion? 论坛帖子

Additional resources