Device Layouts

A device layout is hardware-specific keyboard information, which includes the scan-code-to-virtual-key translations, and virtual-key remapping. For example, a Korean PS/2 keyboard has a different device layout than a Korean matrix keyboard, and a standard English PS/2 keyboard has a different device layout than a Dvorak English PS/2 keyboard.

USB human interface device (HID) keyboard drivers convert universal serial bus (USB) keyboard usage codes to PS/2 Advanced Technology (AT) scan codes, so there is no HID device layout. The HID driver calls MapVirtualKey to retrieve the corresponding virtual key for the scan code, which uses the device layout associated with the first PDD. This sequence occurs so that the localization of scan codes to virtual keys only needs to exist in one place: the device layout. Then, the HID keyboard driver calls keybd_event with the virtual key and scan code.

Many device layouts can correspond to one input language. For example, a standard English device layout and a Dvorak device layout both use US English as the input language.

The Layout Manager performs the scan-code-to-virtual-key mapping. The DeviceLayout.h file describes the related data structures. The Layout Manager performs the remapping after the scan-code-to-virtual-key conversion. Microsoft provides a numeric-pad mapping library for static linking to the device layout's remapping routine so you do not need to duplicate the numeric pad common code. The numeric pad library performs mappings such as VK_NUMPAD0 to VK_INSERT when NUMLOCK is off. The following code example shows the device layout data structures.

// Remapping function typedefs
typedef UINT (*PFN_KEYBD_REMAP)(
  const KEYBD_EVENT *pKbdEvents, 
  UINT cKbdEvents,
  KEYBD_EVENT *pRmpKbdEvents,  
  UINT cMaxRmpKbdEvents 
);

typedef struct tagDEVICE_LAYOUT {
  DWORD dwSize;
  WORD wPddMask; // Matches the device layout with its PDD

  // Scan code to virtual key
  ScanCodeToVKeyData **rgpscvk;
  UINT cpscvk;

  // Remapping functions
  PFN_KEYBD_REMAP pfnRemapKey;
} DEVICE_LAYOUT, *PDEVICE_LAYOUT;

typedef BOOL (*PFN_DEVICE_LAYOUT_ENTRY)(PDEVICE_LAYOUT pDeviceLayout);

The wPddMask members of the PDD data structure and device layout data structure match the device layout to a PDD. The wPddMask member is a bitmask that can correlate one device layout to multiple PDD types. For example, an AT scan code device layout can correlate to both an AT PS/2 PDD and a no operation instruction (NOP) PDD.

See Also

Layout Manager | Device Layout Data

 Last updated on Tuesday, May 18, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.