The Keyboard Driver

Windows is shipped with several keyboard drivers for the support of various keyboard hardware and dynamic link libraries that support international keyboard configurations. Keyboards for European languages must include additional characters (such as letters with diacritics) and symbols (such as the British pound sign). When you install Windows, the SETUP program copies the keyboard driver for the keyboard and country you request into the SYSTEM subdirectory of your Windows directory.

KEYBOARD.DRV is a relatively small and simple driver. When Windows starts up, it enables the keyboard driver, which responds by saving the original interrupt vector addresses for Interrupt 09H (the hardware keyboard interrupt) and setting this interrupt vector to routines within the driver.

Pressing or releasing a key generates an Interrupt 09H. This is sometimes called an ”asynchronous“ interrupt because it can occur at any time. The interrupt suspends the program currently running and passes control to the Interrupt 09H keyboard handler. When the keyboard handler is finished, it passes control back to the interrupted program. The Interrupt 09H keyboard handler within KEYBOARD.DRV decodes the key and calls a routine within the Windows USER module, which stores them as queued messages. The Windows program then obtains the keyboard messages when the program calls GetMessage.

Because a Windows program effectively polls for keyboard input by calling GetMessage, Windows programs are not very different from PC programs that obtain keystrokes by polling through the software Interrupts 16H and 21H. However, the quantity of information that Windows encodes in the keyboard messages is much greater than that available from Interrupts 16H and 21H.

Some application programs written for the IBM PC intercept Interrupt 09H and do their own hardware keyboard processing. This allows the program to use all possible combinations of keystrokes, not only those defined by the PC BIOS. Windows programs are not very different from these programs either, because the window procedure is a message handler that receives messages about all keyboard events. The only real difference between message handling and interrupt handling is that the Windows messages are not asynchronous. A Windows program is never interrupted to be notified of a keystroke; the program receives a new keyboard message only from the message queue. In short, Windows provides programs with all the benefits of intercepting the hardware Interrupt 09H but with none of the hassles.

When a user types on the keyboard faster than a program can process the keys, Windows stores the extra keystrokes in a system message queue rather than in an individual program's message queue. One of these extra keystrokes (Alt-Tab, for instance) may have the effect of switching to another program. The keys following Alt-Tab should then go to the other program. Windows correctly synchronizes such keyboard messages.

Windows sends eight different messages to programs to indicate various keyboard events. That may seem like a lot, but your program can safely ignore many of them.