Microsoft DirectX 8.1 (Visual Basic) |
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 0.
You must also declare an array of DIDEVICEOBJECTDATA types. This array can have up to the same number of elements as the buffer size. You do not have to retrieve the entire contents of the buffer with a single call. You can have just one element in the array and retrieve events one at a time until the buffer is empty.
After acquiring the keyboard device, you can examine and flush the buffer at any time by using the DirectInputDevice8.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 Microsoft® DirectInput® gets the data directly from the keyboard, any settings for character repeat in Control Panel are ignored. This means that a keystroke is counted only 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 lOfs member of the DIDEVICEOBJECTDATA type against the constants in the CONST_DIKEYFLAGS enumeration. (See also Interpreting Keyboard Data.)
The data for the change of state of the key is located in the lData member of the DIDEVICEOBJECTDATA type. Only the low byte of lData is significant. The high bit of this byte is set if the key was pressed, and it is clear if it was released. In other words, the key was pressed if (lData And &H80) is nonzero.