How do i access joystick digital pad in DirectInput8?

167 views Asked by At

Have been looking and searching and i cannot find how to access Joystick D-Pad in Dinput8. We have the DIJOYSTATE2 structure where it gets its info, but don't know what to choose. I know that rgb_butoons[] array holds the buttons info, and that lX and lY the analog stick.

Still don't know the D-Pad (cross)

1

There are 1 answers

2
Ducky On

I believe rgdwPOV is what you're after. I'm assuming you've created your device, SetDataFormat(&c_dfDIJoystick2) and Acquired it.

I shift the state of the DPADs into a 16-bit int so that each bit represents 1 of the directions in each of the DPADs, 4-bits for each DPAD (up,down,left,right).

Here's an example in C++:

DIJOYSTATE2 DeviceState;
HRESULT hr = DIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &DeviceState);

uint16_t rgdwPOV = 0;
for (int i = 0; i < 4; i++) { // In banks of 4, shift in the sate of each DPAD 0-16 bits 
  switch (DeviceState.rgdwPOV[i]) {
    case 0:     rgdwPOV |= (byte)(1 << ((i + 1) * 0)); break; // dpad[i]/up, bit = 0
    case 18000: rgdwPOV |= (byte)(1 << ((i + 1) * 1)); break; // dpad[i]/down, bit = 1
    case 27000: rgdwPOV |= (byte)(1 << ((i + 1) * 2)); break; // dpad[i]/left, bit = 2
    case 9000:  rgdwPOV |= (byte)(1 << ((i + 1) * 3)); break; // dpad[i]/right, bit = 3
  }
}