✅ Windows Joystick API

What's the recommended Windows API to use for Joystick/Gamepad input these days if one needs background (non-focused window, problem for Windows.Gaming.Input) input, and one is not willing to take a dependency on the GDK (Read: No GameInput) whilst also being able to read independently the two triggers of the Xbox-style gamepad controllers (Problem for DirectInput) and working with various types of controllers that are NOT XInput-compatible (Like the PS4 controllers, problem for XInput) ?
20 Replies
Jester
Jester2y ago
Raw Input - Win32 apps
This section describes how the system provides raw input to your application and how an application receives and processes that input.
RazorSharpFang
RazorSharpFangOP2y ago
I am a bit intimidated by the RawInput APIs catsweat
Jester
Jester2y ago
i dont think its as bad as it looks
RazorSharpFang
RazorSharpFangOP2y ago
If you want joystick and button inputs it looks like you have to start using these APIs HidP_GetUsages https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/hidpi/nf-hidpi-hidp_getusages
HidP_GetUsages function (hidpi.h) - Windows drivers
The HidP_GetUsages routine returns a list of all the HID control button usages that are on a specified usage page and are set to ON in a HID report.
Jester
Jester2y ago
uhm does this help u?
RazorSharpFang
RazorSharpFangOP2y ago
No, that's for keyboard and mouse input, not for joystick/gamepad input
Jester
Jester2y ago
just a small change to the register code to change it to joystick
RazorSharpFang
RazorSharpFangOP2y ago
Okay but I'm struggling with actually getting the joystick state from the device
Jester
Jester2y ago
<:PES_SadShrug:646092743378206760>
RazorSharpFang
RazorSharpFangOP2y ago
To be clear, I'm struggling most with getting the state from the HID device, not registering for raw-input
WM_INPUT: Type: 2, Device: 0x717c0911, Size: 16, Count: 1, data: 0, GetRawInputDeviceInfoW says buffer size of 940 required. We have 1 buttons and 6 axes I think you have 16 buttons
Is one of my app's log statements. Does an Xbox controller really have 16 buttons?
Jester
Jester2y ago
i have no idea i dont know much about controllers
RazorSharpFang
RazorSharpFangOP2y ago
HidP_GetUsages returns only those buttons in usage which are actually pressed.
catthinking can confirm with much misery and with great lamentations that RawInput suffers from the same limitation that DirectInput has; it groups the left and right triggers as a single analog input rather than two discrete separate inputs. This literally ruins my entire purpose of trying to use RawInput. This makes me very sad.
RazorSharpFang
RazorSharpFangOP2y ago
I may have to instead use DirectInput and ignore XInput capable devices https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-directinput
Comparison of XInput and DirectInput features - Win32 apps
Compares XInput and DirectInput APIs and features.
RazorSharpFang
RazorSharpFangOP2y ago
I have no idea how to associate a DirectInput device that is an XInput device with a specific XInput user index
sibber
sibber2y ago
yes 4 (abxy) + 4 (dpad) + 2 (joysticks) + 1 (menu) + 1 (button next to menu) + 2 (bumpers) + 2 (triggers)
RazorSharpFang
RazorSharpFangOP2y ago
The dpad is registered as one value provider instead of a series of buttons.
sibber
sibber2y ago
oh
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
RazorSharpFang
RazorSharpFangOP2y ago
I do not have nor have found any good solutions to this, without taking the dependency on the GDK and utilizing GameInput, which is only going for work for Windows 10+ and may require a redistributable for older builds of Windows 10 that haven't received the Windows Gaming Services updates that supply the computer with the required runtime and libraries.
Want results from more Discord servers?
Add your server