The keyboard driver converts input from the keyboard hardware into keyboard events that are fed into the input system. Next, the driver generates the proper Unicode characters from these keyboard events. The Platform Builder includes a keyboard driver that is divided into blocks, which facilitates development of keyboard drivers for international keyboard layouts. This driver can be found under \Platform\ODO\Drivers\Keybd2.
The keyboard driver contains two functions, ScanCodeToVKeyEx and KeybdDriverVKeyToUnicode, that control how keyboard scan codes are translated into virtual keys and Unicode characters. These functions are based on translation tables, which can be customized for different languages. For translation tables for Brazilian Portuguese, Dutch, French, German, Italian, Japanese, Portuguese, Spanish, Swedish, UK English, and US English, see Keyboard Mapping. You can create your own translation tables or customize the existing tables, if necessary.
The sample code shows a design that works for the standard Windows CE–based keyboard layout. By replacing the PDD layer, developers have implemented drivers for hardware that uses software scanning, hardware scanning, and a dedicated keyboard controller. Unusual hardware or nonstandard keyboard layouts might require modification of both the MDD and PDD layers. You can change the MDD layer to build a custom Keybdmdd.lib. Source code for the MDD layer is located under \Public\Common\Oak\Drivers.
The Windows CE input system loads the keyboard driver at startup time. When the input system starts, it retrieves the name of the keyboard driver DLL from the HKEY_LOCAL_MACHINE\Hardware\DeviceMap\KEYBD\Drivername registry key. If no entry is found, the input system uses the default name, Keybddr.dll. It then loads the DLL and verifies that all required entry points exist.
Next, the input system calls the KeybdDriverInitialize function to perform a one-time initialization. In this function, the MDD saves a local copy of the input system callback function. The MDD also calls the KeybdPdd_InitializeDriver function, which starts a thread to handle keyboard interrupts, and then returns to the input system.
In the sample MDD, the IST of the keyboard driver is named KeybdDriverThread. This thread calls the InterruptInitialize function to register for the SYSINTR_KEYBOARD interrupt, and then waits for the system to issue SYSINTR_KEYBOARD signals. When it receives those signals, the interrupt handler calls the KeybdPdd_GetEvent function. The interrupt handler sends the key events returned from the PDD to the input system, which queues them for distribution to applications.
When the input system pulls the keyboard event from the queue, it invokes a callback to the driver’s KeybdDriverVKeyToUnicode routine. The driver analyzes the specified key event and the virtual key state and generates the corresponding characters. The input system then sends the virtual key and the characters to the appropriate application.
The KeybdDriverGetInfo and KeybdDriverSetMode functions get and set information about the keyboard. When the main input thread processes a keyboard-connection event, the thread calls the KeybdDriverGetInfo function to get the virtual-key-to-Unicode data supplied by the driver. The thread also allocates the required memory for the virtual key state data and any extra data required by the driver. Next, it calls the KeybdDriverInitStates function to initialize the memory.
The following table shows the DDI functions for the keyboard driver.
KeybdDriverGetInfo | KeybdDriverSetMode |
KeybdDriverInitialize | KeybdDriverVKeyToUnicode |
KeybdDriverInitStates | KeybdEventCallback |
KeybdDriverPowerHandler |
The following table shows the DDSI functions for the keyboard driver.
KeybdPdd_DllEntry |
KeybdPdd_GetEvent |
KeybdPdd_InitializeDriver |
KeybdPdd_PowerHandler |