Microsoft DirectX 9.0

Immediate Keyboard Data

To retrieve the current state of the keyboard, call the IDirectInputDevice8::GetDeviceState method with a pointer to an array of 256 bytes that will hold the returned data.

The IDirectInputDevice8::GetDeviceState method behaves in the same way as the Microsoft?Win32® GetKeyboardState function. It returns a snapshot of the current state of the keyboard. Each key is represented by a byte in the array of 256 bytes whose address was passed as the lpvData parameter. If the high bit of the byte is set, the key is down. The array is most conveniently indexed with the Microsoft DirectInput® Keyboard Device. (See also Interpreting Keyboard Data.)

The following code example calls a function in response to the ESC key being down. Assume that lpdiKeyboard is an acquired DirectInput device.

BYTE  diKeys[256]; 
if (lpdiKeyboard->GetDeviceState(256, diKeys) == DI_OK) 
  if (diKeys[DIK_ESCAPE] & 0x80) DoSomething(); 

© 2002 Microsoft Corporation. All rights reserved.