To retrieve the current state of the keyboard, call the IDirectInputDevice::GetDeviceState method with a pointer to an array of 256 bytes that will hold the returned data.
The GetDeviceState method behaves in the same way as the Win32 GetKeyboardState function, returning 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 DirectInput Keyboard Device Constants. (See also Interpreting Keyboard Data.)
Here is an example that does something in response to the ESC key being down:
// LPDIRECTINPUTDEVICE lpdiKeyboard; // previously initialized
// and acquired
BYTE diKeys[256];
if (lpdiKeyboard->GetDeviceState(256, diKeys) == DI_OK)
{
if (diKeys[DIK_ESCAPE] & 0x80) DoSomething();
}