Enabling and Disabling the Driver

When Windows is ready to receive keyboard input, it enables the driver by calling the Enable function. When Windows no longer requires keyboard input (when terminating or switching to a full-screen MS-DOS application, for example), it disables the driver by calling the Disable function.

The Enable function is responsible for:

When Windows calls Enable, it passes the address of the keyboard-event callback function. Enable saves this address - the keyboard-interrupt handler uses it to pass scan and virtual-key codes back to Windows.

Windows also passes the address of its 256-element, virtual-key state array (sometimes called the keyboard-state vector) to Enable. The elements in this array specify the state of the virtual keys. Windows sets bit 7 in an element if the corresponding virtual key is down, and clears the bit if the key is up. Similarly, Windows toggles bit zero each time the virtual key is pressed. Although Windows maintains the key-state array, Enable initializes the array to reflect to current state of the SHIFT, CTRL, ALT, NUMLOCK, CAPSLOCK, and SCROLLLOCK keys as specified by the keyboard flags in the RAM area used by the ROM BIOS. (On most computers, the keyboard flags are at address 40h:17h.)

Note

If the keyboard driver reads data from the ROM BIOS, it must use the special segment selector, __ROMBIOS, to create ROM BIOS addresses. The selector (exported by the Windows kernel as KERNEL.173) corresponds to ROM BIOS address 0F0000H.

To install the driver's own keyboard-interrupt handler, the Enable function first saves the existing keyboard-interrupt handler. (On most computers, the keyboard interrupt is Interrupt 9.) The original handler address is saved to allow the Disable function to restore it as well as to allow the driver to call the original handler for certain actions. Enable should also save the address of the Keyboard Service routine (Interrupt 16h). The Enable and other functions use this address to set the keyboard lights.

Note

To support computers in which the keyboard and mouse use the same interrupt, Windows disables and enables both the keyboard and mouse drivers when switching to and from a full-screen MS-DOS application. Windows always enables the drivers in the reverse order in which it disables the drivers.

See also Disable, Enable