To retrieve the current state of the joystick, call the IDirectInputDevice::GetDeviceState method with a pointer to a DIJOYSTATE or DIJOYSTATE2 structure, depending on whether the data format was set with c_dfDIJoystick or c_dfDIJoystick2. (See Device Data Formats.) The joystick state returned in the structure includes the coordinates of the axes, the state of the buttons, and the state of the point-of-view controllers.
The first seven members of the DIJOYSTATE structure hold the axis coordinates. The last of these, rglSlider, is an array of two values. (See Interpreting Joystick Axis Data.)
The rgdwPOV member contains the position of up to four point-of-view controllers in hundredths of degrees clockwise from north (or forward). The center position is reported as -1. For controllers that have only five positions, dwPOV will be one of the following values:
-1 |
0 |
90 * DI_DEGREES |
180 * DI_DEGREES |
270 * DI_DEGREES. |
Note Some drivers report a value of 65,535 instead of -1 for the neutral position. You should check for a centered POV indicator as follows:
BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);
The rgbButtons member is an array of bytes, one for each of 32 or 128 buttons, depending on the data format. For each button, the high bit is set if the button is down and clear if the button is up or not present.
The DIJOYSTATE2 structure has additional members for information about the velocity, acceleration, force, and torque of the axes.
See also Buffered and Immediate Data.