Archive: Scan Code Mapper for Windows
Updated: December 4, 2001
In Microsoft Windows operating systems, PS/2-compatible scan codes provided by an input device are converted into virtual keys, which are propagated through the system in the form of Windows messages. If a device produces an incorrect scan code for a certain key, the wrong virtual key message will be sent. This can be fixed by writing a filter driver that analyzes the scan codes generated by firmware and modifies the incorrect scan code to one understood by the system. However, this is a tedious process and can sometimes lead to severe problems, if errors exist in the kernel-level filter driver.
Windows 2000 and Windows XP include a new Scan Code Mapper, which provides a method that allows for mapping of scan codes. The scan code mappings for Windows are stored in the following registry key:
IMPORTANT: There is also a Keyboard Layouts key (notice the plural form) under the Control key, but that key should not be modified.
In the Keyboard Layout key, the Scancode Map value must be added. This value is of type REG_BINARY and has the data format specified in the following table.
The first and second DWORDS store header information and should be set to all zeroes for the current version of the Scan Code Mapper. The third DWORD entry holds a count of the total number of mappings that follow, including the null terminating mapping. The minimum count would therefore be 1 (no mappings specified). The individual mappings follow the header. Each mapping is one DWORD in length and is divided into two WORD length fields. Each WORD field stores the scan code for a key to be mapped.
Once the map is stored in the registry, the system must be rebooted for the mappings to take effect. Note that if the mapping of a scan code is necessary on a keypress, the step is performed in user mode just before the scan code is converted to a virtual key. Doing this conversion in user mode can present certain limitations, such as mapping not working correctly when running under Terminal Services.
The following presents an example. To swap the left CTRL key with the CAPS LOCK key, use a registry editor (preferably Regedt32.exe) to modify the registry key described earlier. The following value is stored in the Scancode Map key:
00000000 00000000 03000000 3A001D00 1D003A00 00000000
It is important to remember that entries stored in the registry are always in little Endian format. The following table contains these entries broken into DWORD fields and the bytes swapped.
To remove these mappings, the following registry value must be deleted and then the system must be rebooted:
It is also possible to add a key not generally available on a keyboard or to remove a key that is never used. The following example shows the value stored in Scancode Map to remove the right CTRL key and change the functionality of the right ALT key to work as a mute key:
00000000 00000000 03000000 00001DE0 20E038E0 00000000
After the necessary data is generated, it can be inserted into the registry in several ways.
The Scan Code Mapper has several advantages and disadvantages. The advantages include:
The following disadvantages are recognized: