To retrieve buffered data from the keyboard, you must first set the buffer size (see Device Properties). This step is essential, because the default size of the buffer is zero. You then declare an array of DIDEVICEOBJECTDATA structures with the same number of elements as the buffer size.
After acquiring the keyboard device, you can examine and flush the buffer anytime by using the IDirectInputDevice::GetDeviceData method. (See Buffered and Immediate Data.)
Each element in the DIDEVICEOBJECTDATA array represents a change in state for a single key; that is, a press or release. Because DirectInput gets the data directly from the keyboard, any settings for character repeat in Control Panel are ignored. This means that a keystroke is only counted once, no matter how long the key is held down.
You can determine which key an element in the array refers to by checking the dwOfs member of the DIDEVICEOBJECTDATA structure against the DirectInput Keyboard Device Constants. (See also Interpreting Keyboard Data.)
The data for the change of state of the key is located in the dwData member of the DIDEVICEOBJECTDATA structure. Only the low byte of dwData is significant; the high bit of this byte is set if the key was pressed and clear if it was released. In other words, the key was pressed if (dwData & 0x80) is non-zero.