Difference between revisions of "Xmodmap"

From ArchWiki
Jump to: navigation, search
(Additional resources)
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Input devices (English)]]
+
[[Category:Input devices]]
[[Category:X Server (English)]]
+
[[Category:X Server]]
{{i18n|Xmodmap}}
+
 
[[fr: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 16: Line 14:
  
 
== Introduction ==  
 
== Introduction ==  
The Linux kernel generates a code each time a key is pressed on a keyboard. That code is compared to a ''table of keycodes'' defining a figure that is then displayed.
+
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.
  
This process is complicated by [[Xorg]], which starts its own table of keycodes. Each keycode can belong to a ''keysym''. A keysym is like a function, started by typing a key. Xmodmap allows you to edit these keycode-keysym relations.
+
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.
  
 
== Keymap table ==
 
== Keymap table ==
 
Print the current keymap table formatted into expressions:
 
Print the current keymap table formatted into expressions:
{{Command|name=xmodmap -pke|output=keycode  57 = n N}}
+
{{hc|$ xmodmap -pke|2=keycode  57 = n N}}
  
Each keymap is followed by the keysyms it is mapped to. The above example indicates that the keycode {{codeline|57}} is mapped to the lowercase ''n'' keysym, while the uppercase ''N'' keysym is mapped to keycode 57 and shift.
+
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}}.
  
 
Each keysym column in the table corresponds to a particular key combination:
 
Each keysym column in the table corresponds to a particular key combination:
# key
+
# {{Keypress|Key}}
# shift + key
+
# {{Keypress|Shift+Key}}
# mode_switch + key
+
# {{Keypress|mode_switch+Key}}
# mode_switch + shift + key
+
# {{Keypress|mode_switch+Shift+Key}}
# AltGr + key
+
# {{Keypress|AltGr+Key}}
# AltGr + shift + key
+
# {{Keypress|AltGr+Shift+Key}}
  
Not all keysyms have to be set, but if you want to assign a later keysym without assigning earlier ones set the earlier keysyms to {{codeline|NoSymbol}}.
+
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}}.
  
You can check which keymap corresponds to a key on your keyboard with xev (see: [[Extra Keyboard Keys#Using xev|Using xev]]).
+
You can check which keymap corresponds to a key on your keyboard with [[Extra Keyboard Keys#Using xev|xev]].
  
{{tip|There are predefined descriptive keycodes that make mapping additional keys easier (e.g. {{codeline|XF86AudioMute}}, {{codeline|XF86Mail}}). Those keycodes can be found in: {{filename|/usr/includ/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 ==
You can create your own map and store it in your home directory (i.e. {{filename|~/.Xmodmap}}). Print the current keymap table into a configuration file:
+
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:
 
  xmodmap -pke > ~/.Xmodmap
 
  xmodmap -pke > ~/.Xmodmap
  
Make the desired changes to {{filename|~/.Xmodmap}} and then test the new configuration with:
+
Make the desired changes to {{ic|~/.Xmodmap}} and then test the new configuration with:
 
  xmodmap ~/.Xmodmap
 
  xmodmap ~/.Xmodmap
  
 
To activate your custom table when starting Xorg add the following:
 
To activate your custom table when starting Xorg add the following:
{{File|name=~/.xinitrc|content=
+
{{hc|~/.xinitrc|
 
if [ -f $HOME/.Xmodmap ]; then
 
if [ -f $HOME/.Xmodmap ]; then
 
     /usr/bin/xmodmap $HOME/.Xmodmap
 
     /usr/bin/xmodmap $HOME/.Xmodmap
 
fi}}
 
fi}}
  
Alternatively, edit the global startup script: {{filename|/etc/X11/xinit/xinitrc}}.
+
Alternatively, edit the global startup script {{ic|/etc/X11/xinit/xinitrc}}.
  
 
=== Test changes ===
 
=== Test changes ===
Line 62: Line 60:
 
== Special keys/signals ==
 
== Special keys/signals ==
  
You can also also edit the keys: shift, ctrl alt and super (there always exists a left and a right one (Alt_R=AltGr))
+
You can also also edit the keys: {{Keypress|Shift}}, {{Keypress|Ctrl}}, {{Keypress|Alt}} and {{Keypress|Super}} (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. Write at the beginning of your Xmodmap file (here: ~/.xmod) :
+
At first you have to delete/clear the signals that should be edited. In the beginning of your {{ic|~/.Xmodmap}}:
 
  !clear Shift
 
  !clear Shift
 
  !clear Lock
 
  !clear Lock
Line 75: Line 73:
 
  keycode  8 =
 
  keycode  8 =
 
  ...
 
  ...
Remember: ! is a comment. So only Control and Mod4 (Standard: Super_L Super_R) get cleared.
+
Remember, {{ic|!}} is a comment so only {{Keypress|Control}} and {{Keypress|Mod4}} (Standard: Super_L Super_R) get cleared.
  
Write the new signals at the end of ~/.xmod:
+
Write the new signals at the end of {{ic|~/.Xmodmap}}
 
  keycode 255 =
 
  keycode 255 =
 
  !add Shift  = Shift_L Shift_R
 
  !add Shift  = Shift_L Shift_R
Line 87: Line 85:
 
  add Mod4    = Control_L Control_R
 
  add Mod4    = Control_L Control_R
 
  !add Mod5    =
 
  !add Mod5    =
Here: We exchanged the Super-keys with the ctrl-keys. My lil' finger likes that really ;).
+
The {{Keypress|Super}} keys have now been exchanged with the {{Keypress|Ctrl}} 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 {{ic|~/.Xmodmap}}.
 +
 
 +
Open {{ic|~/.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, [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.
  
 
== Additional resources ==
 
== Additional resources ==
Line 95: Line 105:
 
*[http://en.gentoo-wiki.com/wiki/Multimedia_Keys Multimedia Keys article] on the [http://en.gentoo-wiki.com/ Gentoo Wiki]
 
*[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://rollingrelease.com/system/2010/09/xmodmap-hints-and-tips xmodmap Hints and Tips] on [http://rollingrelease.com/ Rolling Release]

Revision as of 14:14, 13 June 2012

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.

Introduction

The Linux kernel generates a code each time a key is pressed on a keyboard. That code is compared to a table of keycodes defining a figure that is then displayed.

This process is complicated by Xorg, which starts its own table of keycodes. Each keycode can belong to a keysym. A keysym is like a function, started by typing a key. Xmodmap allows you to edit these keycode-keysym relations.

Keymap table

Print the current keymap table formatted into expressions:

$ xmodmap -pke
keycode  57 = n N

Each keymap is followed by the keysyms it is mapped to. The above example indicates that the keycode 57 is mapped to the lowercase n, while the uppercase N is mapped to keycode 57 and Shift.

Each keysym column in the table corresponds to a particular key combination:

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

Not all keysyms have to be set, but if you want to assign a latter keysym without assigning earlier ones set them to NoSymbol.

You can check which keymap corresponds to a key on your keyboard with xev.

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