Reputation: 1526
I am using the raw input API to write a simple program for my Xbox controller. I have followed the basic setup steps from https://learn.microsoft.com/en-us/windows/win32/inputdev/using-raw-input and am able to get the dara for all the buttons and all. The problem I am facing is it seems that the InputValueCap
for both the trigger buttons are the same thus all i get is a ULONG that is 00000001000000000000000000000000
when right trigger is fully pressed, 00000000000000010000000000000000
when both are released and 00000001111111110000000000000000
when the left trigger is fully pressed, but this is all good when they are being used separately, but whe both are oressed together i get 00000000000000010000000000000000
and in between values when they are pressed midway. My question is how to distinguish left from right when both are being pressed?
The way i am getting these values is:
for (UINT i = 0; i < device->numValueCaps; i++)
{
ULONG value;
if (HidP_GetUsageValue(HidP_Input, device->pValueCaps[i].UsagePage, 0, device->pValueCaps[i].Range.UsageMin, &value, device->pPreParsedData, (PCHAR)raw->data.hid.bRawData, raw->data.hid.dwSizeHid) != HIDP_STATUS_SUCCESS)
{
printf("Error getting usage value\n");
return;
}
gControllerState.wValues[i] = value;
}
Upvotes: 0
Views: 74
Reputation: 1441
DirectInput uses HID API under the hood. RawInput uses HID too. What you're expecting is a limitation of XInput controllers HID interface:
The XUSB controllers are properly enumerated on DirectInput, and can be used with the DirectInputAPIs. However, some functionality provided by XInput will be missing from the DirectInput implementation:
- The left and right trigger buttons will act as a single button, not independently
- The vibration effects will not be available
- Querying for headset devices will not be available
The combination of the left and right triggers in DirectInput is by design. Games have always assumed that DirectInput device axes are centered when there is no user interaction with the device. However, the newer controllers were designed to register minimum value, not center, when the triggers are not being held. Older games would therefore assume user interaction.
The solution was to combine the triggers, setting one trigger to a positive direction and the other to a negative direction, so no user interaction is indicative to DirectInput of the "control" being at center.
In order to test the trigger values separately, you must use XInput.
Upvotes: 1