Open all the attached controllers (the Xbox 360 controller is found and opened):
SDL_GameController* gamepadId[12] = { nullptr };
for (int i = 0; i < SDL_NumJoysticks(); i++)
{
if (!SDL_IsGameController(i))
{
continue;
}
SDL_GameController* g = SDL_GameControllerOpen(i);
gamepadId[numGamepads++] = g;
}
I have SDL_GameControllerUpdate(); in my game loop and query each controller with SDL_GameControllerGetButton and SDL_GameControllerGetAxis. With these I’m able to correctly query button and axis states for my DualSense, DualShock 4, Switch Pro Controller, Power A Pro Controller, and my Logitech Gamepad F310 in DirectInput mode, but not in XInput mode, and not my Xbox 360 controller.
The queries for XInput device states are just returning all false / 0.
I’ve only tried with one or two controllers attached at a time, so XInput’s 4 controller limit shouldn’t be affecting this. I’m using SDL 2.0.14 on Windows 10 64-bit. Is there something else I’m supposed to do to get XInput devices working properly?
Thanks for the suggestions! I’ve tried it just now, and I’m not getting events from XInput devices. Input events come through just fine for other devices I tried (DualSense, F310 in DirectInput mode, Power A).
Seems I having somewhat related issue here.
Workaround is:
SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1");
I looked into SDL code and seems issue was in SDL_CreateDeviceNotification() - it is calling CreateWindowEx with HWND_MESSAGE param and this will not work with RegisterDeviceNotification(). So no connection status updates for pads.
I investigated this issue further.
It turned our that SDL_HINT_JOYSTICK_THREAD fixes this issue only partially: HID gamepads like PS4/PS5 still not detected.
Seems WM_DEVICECHANGE is working regardless of HWND_MESSAGE flag in CreateWindowEx call.
The problem was that I called SDL_PollEvent() (and SDL_PumpEvents() indirectly) in non-main thread and thats is why no WM_DEVICECHANGE arriving into ControllerWndProc (inside SDL_hidapijoystick.c).
I fixed this with creating of a new separate thread with simple windows loop: