NAME
xmodmap − keyboard and pointer modifier utility.
SYNTAX
xmodmap [options] [filename]
DESCRIPTION
xmodmap is a utility for displaying and editing the X keyboard modifier map and keymap table that client applications use to convert keycodes into keysyms. xmodmap is intended to be run from a user’s X startup script to set up the keyboard according to personal tastes.
With no arguments, xmodmap displays the current map. See Chapter 14, Setup Clients, for more information.
OPTIONS
xmodmap accepts the following options:
-display [host]:server[.screen]
Specifies the name of the display to use. host is the hostname of the physical display, server specifies the display server number, and screen specifies the screen number. Either or both of the host and screen elements to the display specification can be omitted. If host is omitted, the local display is assumed. If screen is omitted, screen 0 is assumed (and the period is unnecessary). The colon and (display) server are necessary in all cases. For example: % xmodmap -display your_node:0.0 specifies the screen 0 on server 0 on the display identified by your_node. If the host is omitted, the local display is assumed. If the screen is omitted, the screen 0 is assumed; the server and colon (:) are necessary in all cases. The -display option can be abbreviated as -d, unless the client accepts another option that begins with "d."
-e expression
Specifies an expression to be executed. Any number of expressions may be specified from the command line.
-grammar
Indicates that a help message describing the expression grammar used in files and with -e expressions should be printed on the standard error.
-helpIndicates that a brief description of the command line arguments should be printed on the standard error. This will be done whenever an invalid argument is given to xmodmap.
-quietTurns off the verbose logging. This is the default.
-nIndicates that xmodmap should not change the mappings, but should display what it would do, as make(1) does when given this option. (Cannot be used with expressions to change the pointer mapping.)
-pmIndicates that the current modifier map should be printed on the standard output.
-pkIndicates that the current keymap table should be printed on the standard output.
-pkeIndicates that the current keymap table should be printed on the standard output in the form of expressions that can be fed back to xmodmap.
-ppIndicates that the current pointer map should be printed on the standard output.
-A lone dash means that the standard input should be used as the input file.
-verbose
Indicates that xmodmap should print logging information as it parses its input.
The filename argument specifies a file containing xmodmap expressions to be executed. This file is usually kept in the user’s home directory and has a name like .xmodmaprc.
EXPRESSION GRAMMAR
The xmodmap program reads a list of expressions and parses them all before attempting to execute any of them. This makes it possible to refer to keysyms that are being redefined in a natural way without having to worry as much about name conflicts. Allowable expressions include:
keycode NUMBER = KEYSYMNAME ...
The list of keysyms is assigned to the indicated keycode (which may be specified in decimal, hex, or octal and can be determined by running the xev program in the examples directory).
keysym KEYSYMNAME = KEYSYMNAME ...
The KEYSYMNAME on the left hand side is translated into matching keycodes used to perform the corresponding set of keycode expressions. The list of keysym names may be found in the header file <X11/keysymdef.h> (without the XK_ prefix) or the keysym database /usr/lib/X11/XKeysymDB. Note that if the same keysym is bound to multiple keys, the expression is executed for each matching keycode.
clear MODIFIERNAME
This removes all entries in the modifier map for the given modifier, where valid names are: Shift, Lock, Control, Mod1, Mod2, Mod3, Mod4, and Mod5 (case does not matter in modifier names, although it does matter for all other names). For example, clear Lock will remove any keys that were bound to the lock modifier.
add MODIFIERNAME = KEYSYMNAME ...
This adds all the keys having the given keysyms to the indicated modifier map. The keysym names are evaluated after all input expressions are read to make it easy to write expressions to swap keys. (See the "Examples" section.)
remove MODIFIERNAME = KEYSYMNAME ...
This removes all the keys having the given keysyms from the indicated modifier map. Unlike add, the keysym names are evaluated as the line is read in. This allows you to remove keys from a modifier without having to worry about whether or not they have been reassigned.
pointer = default
This sets the pointer map back to its default settings (button 1 generates a code of 1, button 2 generates a 2, etc.).
pointer = N1 N2 N3
This sets the pointer map to contain the button codes N1, N2, and N3, where N1, N2 and N3 are numbers. The list always starts with the first physical button.
Lines that begin with an exclamation mark (!) are taken as comments.
If you want to change the binding of a modifier key, you must also remove it from the appropriate modifier map.
EXAMPLES
Many pointers are designed such that the first button is pressed using the index finger of the right hand. People who are left handed frequently find that it is more comfortable to reverse the button codes that get generated so that the primary button is pressed using the index finger of the left hand. This could be done on a 3-button pointer as follows: % xmodmap -e "pointer = 3 2 1" Many editor applications support the notion of Meta keys (similar to Control keys except that Meta is held down instead of Control). However, some servers do not have a Meta keysym in the default keymap table, so one needs to be added by hand. The following command will attach Meta to the Multi-language key (sometimes labeled Compose Character). It also takes advantage of the fact that applications that need a Meta key need simply to get the keycode and don’t require the keysym to be in the first column of the keymap table. This means that applications that are looking for a Multi_key (including the default modifier map) won’t notice any change. % xmodmap -e "keysym Multi_key = Multi_key Meta_L" One of the more simple, yet convenient, uses of xmodmap is to set the keyboard’s "rubout" key to generate an alternate keysym. This frequently involves exchanging Backspace with Delete to be more comfortable to the user. If the ttymodes resource in xterm is set as well, all terminal emulator windows will use the same key for erasing characters: % xmodmap -e "keysym BackSpace = Delete" % echo "XTerm∗ttyModes: erase ^?" | xrdb -merge Some keyboards do not automatically generate less than and greater than characters when the comma and period keys are shifted. This can be remedied with xmodmap by resetting the bindings for the comma and period with the following scripts:
!
! make shift-, be < and shift-. be >
!
keysym comma = comma less
keysym period = period greater
One of the more irritating differences between keyboards is the location of the Control and Shift Lock keys. A common use of xmodmap is to swap these two keys as follows:
!
! 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
The keycode expression is useful for assigning the same keysym to multiple keycodes. Although unportable, it also makes it possible to write scripts that can reset the keyboard to a known state. The following script sets the Backspace key to generate Delete (as shown above), flushes all existing caps lock bindings, makes the CapsLock key a control key, makes F5 generate Escape, and makes Break/Reset function as a shift lock.
!
! On the HP, the following keycodes have key caps as listed:
!
! 101 Backspace
! 55 Caps
! 14 Ctrl
! 15 Break/Reset
! 86 Stop
! 89 F5
!
keycode 101 = Delete
keycode 55 = Control_R
clear Lock
add Control = Control_R
keycode 89 = Escape
keycode 15 = Caps_Lock
add Lock = Caps_Lock
SEE ALSO
X, xev; Chapter 14, Setup Clients.
BUGS
Every time a keycode expression is evaluated, the server generates a MappingNotify event on every client. This can cause some thrashing. All of the changes should be batched together and done at once. Clients that receive keyboard input and ignore MappingNotify events will not notice any changes made to keyboard mappings.
xmodmap should generate add and remove expressions automatically whenever a keycode that is already bound to a modifier is changed.
There should be a way to have the remove expression accept keycodes as well as keysyms for those times when you really mess up your mappings.
AUTHORS
Rewritten by Jim Fulton, MIT X Consortium, from an earlier version by David Rosenthal of Sun Microsystems.