[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

General Programming Concepts: Writing and Debugging Programs

Working with Keyboard Mapping

The following model shows how input methods are used by applications. It can help you understand how to customize keyboard mapping.

Input processing is divided into three steps:

  1. keycode/keystate(raw) - > keysym/modifier(new)

    This step is application and environment-dependent. The application is responsible for mapping the raw key event into a keysym/modifier for input to the input method.

    In the AIXwindows environment, the client uses the server's keysym table, xmodmap, which is installed at the server, to perform this step. The xmodmap defines the mapping of the Shift, Lock, and Alt-Graphic keys. The client uses the xmodmap as well as the Shift and Lock modifiers from the X event to determine the keysym/modifier represented by this event.

    For example, if you press the XK_a keysym with a Shift modifier, the xmodmap maps it to the XK_A keysym. Since you used the Shift key to map the key code to a keysym, the application should mask the Shift modifier from the original X event. Consequently, the input to the input method (step 2) would be the XK_A keysym and no modifier.

    In another environment, if the device provides no additional information, the input method receives the XK_a keysym with the Shift modifier. The input method should perform the same mapping in both cases and return the letter A.

  2. keysym/modifier(new) - > localized string

    This step depends on the localized IMED and varies with each locale. It is used to notify the IMED that a key event occurred and to ask for an indication that their IMED uses the key event internally. This occurs when the application calls the IMFilter subroutine.

    If the IMED indicates that the key event is used for internal processing, the application ignores the event. Since the IMED is the first to see the event, this step should be done before the application interprets the event. The IMED only uses key events that are essential.

    If the IMED indicates the event is not used for internal processing, the application performs the next step.

  3. keysym/modifier(new) - > customized string

    This step occurs when the application calls the IMLookupString subroutine. The input method keymap (created by the keycomp command) defines the mapping for this phase. It is the last attempt to map the key event to a string and allows a user to customize the mapping.

    If the keysym/modifier (new) combination is defined in the input method keymap (imkeymap), a string is returned. Otherwise, the key event is unknown to the input method.

IM Keymaps

The input method provides support for user-defined imkeymaps, allowing you to customize input method mapping. The input methods support imkeymaps for each locale. The file name for imkeymaps is similar to that of input methods, except that the suffix for imkeymap files is .imkeymap instead of .im.

Refer to this example of using the Italian input method, which illustrates how you can customize your imkeymap:

  1. To copy the default imkeymap source file to your $HOME directory, enter:

    cd $HOME
    cp /usr/lib/nls/loc/it_IT.ISO8859-1.imkeymap.src .
  2. To edit the imkeymap source file following the default file format, enter:

    vi it_IT.ISO8859-1.imkeymap.src
  3. To compile the imkeymap source file, enter:

    keycomp < it_IT.ISO8859-1.imkeymap.src > it_IT.ISO8859-1.imkeymap
  4. To make sure the LOCPATH variable specifies $HOME before /usr/lib/nls/loc, enter:


    Note: All setuid and setgid programs will ignore the LOCPATH environment variable.

Inbound and Outbound Mapping

The imkeymaps map a key symbol to a file code set string. The localized imkeymaps found in the /usr/lib/nls/loc library are defined to include mapping for all of the inbound keys. The imkeymaps provide two types of mapping:

Inbound mapping Mapping of a keysym/modifier that generates a target string encoded in the code set of the locale.
Outbound mapping Mapping of a keysym/modifier that does not generate a target string included in the code set of the locale.

A special imkeymap, /usr/lib/nls/loc/C@outbound.imkeymap, defines outbound mapping for all keyboards made by this manufacturer and is primarily intended for use by aixterm. This imkeymap includes mapping of PF keys, cursor keys, and other special keys commonly used by applications. Internationalized applications that use standard input and standard output should limit their dependency on outbound mapping, which does not vary on different keyboards. For example, the Alt-a is defined in the same way on all keyboards made by this manufacturer. Yet, the Alt-tilde is different depending on the keyboard used.

The aixterm bases its outbound mapping on the C@outbound imkeymap. Applications that require more mapping should modify the localized imkeymap source to include the necessary definitions.

Related Information

Chapter 16, National Language Support .

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]