Introduction to Xmodmap
Xmodmap is a utility for modifying keymaps in X. It is an X client that allows users to view or change the keymap table of Reflection X or other X servers. The keymap table represents the keycode and associated key symbol name (keysym) mapping for each key on the keyboard of the PC running Reflection X.
The keycode is the number associated with the specific physical location on the keyboard. The keycode cannot be changed. The keysym is the label that specifies a key’s function, and the keysym can be changed. Keysyms can be mapped to different keycodes using a mapping utility such as xmodmap.
Viewing Key Mappings with the Xmodmap Client
To view the keymap table with xmodmap, Reflection X (or another X server) must be running. From an xterm, enter the case-sensitive command:
$ xmodmap -pke | more
Note: You may need the full path of the command if xmodmap is not in the path. Xmodmap is most commonly found in these locations:
This command displays the keymap table and lists the current mapping for each key. For example:
|keycode 194 =
Keycode 194 is the PC’s key number used by Reflection X. (This is actually the Microsoft Windows keycode plus 8.)
Note: Other X servers will assign keycodes differently.
It is common to see two keysyms assigned to a key. The first keysym is sent when the key is used by itself “unmodified.” The second keysym is sent when the key is modified. The SHIFT, CTRL, and CAPS LOCK keys are “modifiers” that provide additional keysyms to alter the action of other keys.
For many non-US and non-Japanese keyboards, the right ALT key, or ALT-GR, is defined as Mode_Switch. To see a list of defined modifiers, run xmodmap at a command line without any options.
In the keymap table, you may notice that several of the keycodes are unassigned. These keycodes do not have an associated keysym because they lack a default PC key assignment (Microsoft Windows keycode).
Changing Key Mappings with the Xmodmap Client
You can change individual key mappings by using the xmodmap command with the –e option. The –e option specifies an xmodmap “expression” (enclosed within apostrophes or quotation marks).
For example, to map the keysym “currency” (the Euro currency symbol) to keycode 253, you would type the following command:
/usr/bin/X11/xmodmap -e 'keycode 253 = currency'
To make multiple changes to your keymap table, choose one of the three options listed below.
- Execute one xmodmap command for each keymap change.
- Write the individual expressions into one text file for xmodmap to load simultaneously. This is faster than running separate xmodmap commands for each expression. For example, if you have a file in your UNIX home directory called Mykeymap that contains the following HP xmodmap expressions:
keycode 53 = InsertChar InsertLine
keycode 54 = DeleteChar DeleteLine
Then, at the host prompt you would type:
- The xmodmap command can also be added to your Reflection X Client Startup so that it will run automatically when you start your X client application.
To automate the xmodmap command at Startup:
- In the Reflection X Client Manager, look in the Connection Settings in the right pane, and click the Advanced button.
- In the Prompt column, find the first blank field, and enter your host’s command prompt ($, #, >, etc.).
- In the corresponding Response column, enter the xmodmap command.
In the following example, the command prompt is $ and the response is xmodmap Mykeymap -d %IP#%&
Using X Clients for Key Mapping
A word of caution when using X clients such as xmodmap for key mapping: By default, these client assignments override whatever is specified in the Reflection X keymap file. If you want to preserve Reflection X key mapping, you will need to follow these steps:
- On the Reflection X Settings menu, click Keyboard.
- Under Options, clear the Allow Clients to Remap Keyboard check box.
Alternate Methods of Determining Current Keycodes and Keysyms
Using xmodmap is only one method of determining current keycode and keysym assignments. The list below describes additional ways of performing this task.
- The xev (X Event Viewer) is an X client that keeps track of two events when a key is pressed: KeyPress and KeyRelease. The events captured by xev include the keycode and keysym information sent.
See the xev man page for more information.
- In Reflection X, you can view keycode and associated keysym values by clicking Keyboard on the Settings menu. In the Keyboard Settings dialog box, select a Host Keyboard, and then click the Customize button.
You will see two keyboards in the Keyboard Remapping dialog box. The top one is the PC’s keyboard; the bottom is the Host’s keyboard. Simply click the desired key to see its keycode and keysym assignment displayed in the Current Key area to the right of the keyboard.
Sometimes third-party applications have a file that contains vendor-specific keysyms. These files are typically called App_keysymdef.h, Sun_keysymdef.h, or HP_keysymdef.h.
- Reflection X Online Help. Go to Help Topics under the Help menu, and then from the Index tab search for “keyboard mapping,” or execute a Find search on xmodmap.
- “X Window System User’s Guide for X11 Release 5,” a book written by Valerie Quercia and Tim O’Reilly.