[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Using the Keyboard

The keyboard class of special devices reports character values when keys, or a combination of keys, are pressed. The following section discusses both international keyboard input and controlling keyboard characteristics and behavior.

List of GL Keyboard Subroutines

clkon, clkoff
                          Turns keyboard click on and off.
lampon, lampoff
                          Turns the keyboard display lights on and off.
                          Rings the keyboard bell.
                          Sets the duration of the keyboard bell sound.
                          Sets the lights on the dial and switch box.

International Keyboard Input

The KEYBD device returns code points that correspond to the keys typed on the keyboard. The manner in which keystrokes are matched with the returned value depends on the locale, a language, territory, and code set combination used to identify a set of language conventions. For example, in United States-English installation, the value returned is the ASCII value that corresponds to the key pressed, taking into account the Shift and Ctrl keys. In other language keyboard installations, encodings from the ISO8859 family of code sets are returned. For further information on code sets, see Code Sets Overview in in AIX General Programming Concepts: Writing and Debugging Programs..

Input Method

The method used for matching up keystrokes to returned values is called the input method. The locale, which determines the key mapping, is determined from the default setting when the system was configured, or from the $LANG environment variable, or from the most recent invocation of the setlocale subroutine. The input method helps correct for different key placements on different keyboards; for instance, the letter Z on the French keyboard appears in the same location as the letter W on the US English keyboard. For further information on input method, see Input Method Overview in in AIX General Programming Concepts: Writing and Debugging Programs.

The input method also automatically takes into account cases where multiple keystrokes are needed to specify one unique letter. The value returned may be a single-byte value (in the case of languages with single-byte code sets), or double-byte value (for languages supporting double-byte code sets). For further information on National Language Support, refer to the National Language Support Overview for Programming in in AIX General Programming Concepts: Writing and Debugging Programs.

In the example of the United States-English keyboard device, events are reported only on a key downstroke. The value returned takes into account the state of the modifier key (the Ctrl, Shift, and Shift-lock keys). Pressing the lowercase letter a on the keyboard returns the ASCII value 0x61, while pressing Shift-A returns the ASCII value 0x41. Similarly, pressing the Ctrl-G key sequence returns BEL (hex value 0x07), the Ctrl-D key sequence returns ETX (hex value 0x03) and so on, proceeding with the standard ASCII mapping.

It is important to understand the difference between the device and the values it returns when you queue the keyboard. If your program contains the following instruction:


then the statement:

dev = qread(&val);

returns the following:

dev == KEYBD
val == the ISO8859 code set encoding of the character pressed.

In United States-English keyboard installations, you can test for individual keystrokes by using instructions with the following format:


This returns the AKEY device when the uppercase A or lowercase a key is pressed.

Note: Currently, the keyboard mapping for KEY devices is guaranteed to be correct only in United States-English installations.

Keyboard Mapping

The actual keyboard mapping used by the KEYBD device is contained in an imkeymap file. The following locations are searched, in the order indicated, for this file:

  1. $XDIR/imkeymap
  2. $HOME/imkeymap
  3. /usr/lib/nls/loc/$LANG

If none of these files are found, the mapping defaults to the ISO8859 (Latin-1) keyboard mapping. An input method determines the mapping. By default, the input method used is IMSimpleMap. For most country and language combinations, two different encodings are supplied: the ISO8859 encoding and the IBM-850 encoding. For example, $LANG = Fr_CH is used to indicate the IBM-850 encoding for Swiss French, while $LANG = fr_FR indicates that the ISO8859-1 encoding should be used.

Note: Changing the locale after initialization has no effect. Keyboard initialization occurs at the time the X server is brought up. Therefore, the locale (or $LANG variable) should be set before the X server is started.

For applications developed for use in countries and languages with more complex input-composing requirements, such as in the Asian/Pacific Rim regions, it is strongly suggested that the AIXwindows input widget be used. Use of AIXwindows for input requires knowledge of the X display connection and the X Window identifier of a GL window for a GL session. This information can be obtained with the GL getXdpy or getXwid subroutines. For a review of limitations, see "Using Enhanced X-Windows Calls with GL Subroutines". Example usages can be found in the /usr/lpp/GL/examples directory.

Alt PF Key Keystroke Sequences

In the normal course of operations, the window manager interprets some key sequences as having special meaning. These key sequences typically involve pressing a PF key while holding down the Alt key, and are used to modify a window by moving, resizing, raising, lowering it, and so on. The window manager removes these events from the event queue, and a GL application requesting these key events does not receive them. The actual keystrokes that are grabbed are under control of the .mwmrc file, and are known as accelerators. Although the default accelerators shipped with the system are Alt-PF key sequences, the user can change or eliminate the key sequences used as menu accelerators by editing the $HOME/.mwmrc file. Note, however, that changes made to the $HOME/.mwmrc file affect all applications. Currently, there is no selective means of disabling the key grabbing for some, but not all, applications.

Controlling the Keyboard

In addition to routines that poll and queue input devices, there are subroutines that control the characteristics and behavior of the GL peripheral input and output devices. For example, some of these subroutines turn the keyboard click on and off (the clkon and clkoff subroutines, respectively) or set the keyboard bell. You set these controls to your preference or needs.

clkon and clkoff Subroutines

The clkon and clkoff subroutines turn the keyboard click on and off. The syntax for the clkon and clkoff subroutines is as follows:

void clkon()
void clkoff()

lampon and lampoff Subroutines

The lampon and lampoff subroutines control the four lamps on the keyboard. Each 1 (as opposed to 0) in the four lower-order bits of the lamps parameter to the lampon subroutine causes the corresponding keyboard lamp to be on or off, depending on the subroutine called. The syntax for the lampon and lampoff subroutines is as follows:

void lampon(Int8 lamps)
void lampoff(Int8 lamps)

ringbell Subroutine

The ringbell subroutine rings the keyboard bell. The syntax is as follows:

void ringbell()

setbell Subroutine

The setbell subroutine sets the duration of the keyboard bell. A value of 0 in the durat parameter is off, 1 is a short beep, and 2 is a long beep. The syntax is as follows:

void setbell(Char8 durat)

setdblights Subroutine

The setdblights subroutine controls the 32 lighted switches on a dial and switch box. For example, to turn on switches 3 and 7, the third and seventh bits of the mask must be set to 1 (1<<3)|(1<<7)=0x88 . The syntax is as follows:

void setdblights(Int32 mask)

[ Previous | Next | Contents | Glossary | Home | Search ]