Microsoft DirectX 8.1 (Visual Basic)

Immediate Keyboard Data

To retrieve the current state of the keyboard, call the DirectInputDevice8.GetDeviceStateKeyboard method, passing a DIKEYBOARDSTATE type.

The GetDeviceState method returns a snapshot of the current state of the keyboard. Each key is represented by an element in the array of 256 bytes that makes up the DIKEYBOARDSTATE type. If the high bit of the byte is set, the key is down. The array is most conveniently indexed with the members of the CONST_DIKEYFLAGS enumeration. (See also Interpreting Keyboard Data.)

The following code example determines whether the ESC key is currently being pressed. Assume that objDIDev is a DirectInputDevice8 object.

Dim KeyState As DIKEYBOARDSTATE
 
Call objDIDev.GetDeviceStateKeyboard(KeyState)
If (KeyState.Key(DIK_ESCAPE) And &H80) Then
    ' Key is down.
End If