HPlogo Using the X Window System > Chapter 9 Customizing the Mouse and Keyboard

Customizing Keyboard Input

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Glossary

 » Index

Besides remapping the mouse's pointer and buttons to your keyboard, you can remap any key on the keyboard to any other key.

Modifying Modifier Key Bindings with `xmodmap'

To change the meaning of a particular key for a particular X11 session, or to initialize the X server with a completely different set of key mappings, use the xmodmap client.

NOTE: There are now two keyboards available for Hewlett-Packard workstations, the 46021 keyboard, and the C1429 keyboard. See appendix B, Using the Keyboards, for more information on using these keyboards and the differences between them.

The syntax for xmodmap is as follows:

   xmodmap options [filename]

where options are:

-display host:display

Specifies the host, display number, and screen to use.

-help

Displays a brief description of xmodmap options.

-grammar

Displays a brief description of the syntax for modification expressions.

-verbose

Prints log information as xmodmap executes.

-quiet

Turns off verbose logging. This is the default.

-n

Lists changes to key mappings without actually making those changes.

-e expression

Specifies a remapping expression to be executed.

-pm, -p

Prints the current modifier map to the standard output. This is the default.

-pk

Prints the current keymap table to the standard output.

-pp

Print the current pointer map to the standard output.

-

Specifies that the standard input should be used for the input file.

filename

Specifies a particular key mapping file to be used.

Specifying Key Remapping Expressions

Whether you remap a single key "on the fly" with a command-line entry or install an entire new keyboard map file, you must use valid expressions in your specification, one expression for each remapping.

A valid expression is any one of the following:

Table 9-10 Valid `xmodmap' Expressions.

To do this...Use this expression...
Assign a key symbol to a keycode.keycodekeycode=keysym
Replace a key symbol expression with another. keysymkeysym =keysym
Clear all keys associated with a modifier key.clearmodifier
Add a key symbol to a modifier.addmodifier=keysym
Remove a key symbol from a modifier.removemodifier=keysym

 

keycode

Refers to the numerical value that uniquely identifies each key on a keyboard. Values may be in decimal, octal, or hexadecimal.

keysym

Refers to the character symbol name associated with a keycode, for example, KP_Add.

modifier

Specifies one of the eight modifier names.

The following are the modifier names available for use in keyboard customization:

Table 9-11 Valid Modifier Names.

Modifier Names
ShiftControlMod2Mod4
LockMod1Mod3Mod5

 

On Hewlett-Packard keyboards, the lock modifier is set to the Caps key. However, any of the modifiers can be associated with any valid key symbol. Additionally, you can associate more than one key symbol with a modifier (such as Lock = Shift_R and Shift_L), and you can associate more than one modifier with a key symbol (for example, Control = Caps_Lock and Lock = Caps_Lock).

For example, on a PC-style keyboard, you can press d to print a lower case "d", Shift d to print a capital "D", Alt d to print something else, and Shift Alt d to print still something else.

The xmodmap client gives you the power to change the meaning of any key at any time or to install a whole new key map for your keyboard.

Examples

Suppose you frequently press the Caps key at the most inopportune moments. You could remove the Caps lock key from the lock modifier, swap it for the f1 key, then map the f1 key to the lock modifier. Do this is by creating a little swapper file that contains the following lines:

   !This file swaps the [Caps] key with the [F1] key.



   remove Lock = Caps_Lock

   keysym Caps_Lock = F1

   keysym F1 = Caps_Lock

   add Lock = Caps_Lock

Note the use of the ! in the file to start a comment line. To put your "swapper" file into effect, enter the following on the command line:

   xmodmap swapper

If you use such a swapper file, you should probably have an unswapper file. The following file enables you to swap back to the original keyboard mapping without having to exit X11:

   !This file unswaps the [F1] key with the [Caps] key.



   remove Lock = Caps_Lock

   keycode 88 = F1

   keycode 55 = Caps_Lock

   add Lock = Caps_Lock

Note the use of the hexadecimal values to reinitialize the keycodes to the proper key symbols. You put your "unswapper" file into effect by entering the following command line:

   xmodmap unswapper

On a larger scale, you can change your current keyboard to a Dvorak keyboard by creating a file with the appropriate keyboard mappings.

   xmodmap .keymap

Printing a Key Map

The -pk option prints a list of the key mappings for the current keyboard.

   xmodmap -pk

The list contains the keycode and up to four 2-part columns. The first column contains unmodified key values, the second column contains shifted key values, the third column contains meta (Extend char) key values, and the fourth column contains shifted meta key values. Each column is in two parts: hexadecimal key symbol value, and key symbol name.

© 1995 Hewlett-Packard Development Company, L.P.