0

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)

Lucas
  • 329
  • 1
  • 8

1 Answers1

0

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
  }
}
Ducky
  • 184
  • 15
  • You need to initialize `rgdqPOV` before the loop, otherwise the `|=` operators are combining with garbage (formally undefined behavior) – Ben Voigt Sep 08 '21 at 17:20
  • Cheers. Had simplified this snippet from one of my own projects, never tested it – Ducky Sep 08 '21 at 20:15