Platform SDK: DirectX

Immediate Joystick Data

[C++]

To retrieve the current state of the joystick, call the IDirectInputDevice7::GetDeviceState method with a pointer to a DIJOYSTATE or a 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 seven, 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 a degree clockwise from north (or forward). The center position is reported as –1. For controllers that have only five positions, the position is one of the following values:

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.

[Visual Basic]

To retrieve the current state of the joystick, call the DirectInputDevice.GetDeviceStateJoystick or the DirectInputDevice.GetDeviceStateJoystick2 method, depending on whether the data format was set with DIFORMAT_JOYSTICK or DIFORMAT_JOYSTICK2. (See Device Data Formats.) The joystick state returned in the state parameter includes the coordinates of the axes, the state of the buttons, and the state of the point-of-view controllers.

The POV member of the DIJOYSTATE or the DIJOYSTATE2 type contains the position of up to four point-of-view controllers in hundredths of a degree clockwise from north (or forward). The center position is reported as –1. For controllers that have only five positions, the position is one of the following values:

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:

Dim POVCentered As Boolean
POVCentered = (dwPOV And &HFFFF) = &HFFFF;

The buttons member is an array of bytes, one for each of 32 or 128 buttons, depending on the data type. 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 type has additional members for information about the velocity, acceleration, force, and torque of the axes.

For more information, see Interpreting Joystick Axis Data.

See also

Buffered and Immediate Data