Handmade Hero»Forums»Code
51 posts
XInput detect Generic USB controller?
Edited by vexe on
Greetings!

So I have this generic USB 'Genius' controller. I loaded the xinput dll and all the necessary functions but it doesn't seem to be able to detect my controller. MSDN says xinput is for XBox controllers but I do remember Casey mentioning that a lot of controllers have an xinput driver.

So I was wondering if there's a way to 'fake' it to the OS make it look like that my controller is an Xbox 360 one. I did find an xbox 360 controller emulator but it's mostly for games, i.e. they require you to copy/paste to your game's exe folder. I'm not sure how that would work in my case.

Any help/tips are appreciated.

vexe/elxenoanizd
Mārtiņš Možeiko
2563 posts / 2 projects
XInput detect Generic USB controller?
Yeah, I don't think you will find anything better. If your generic controller doesn't support xinput natively, then you need to copy custom xinput dll file next to game, which will translate DirectInput input to xinput. This utility does that: http://www.x360ce.com/

For specific controllers like DualShock3/4 you can find a bit better software that will emulate xinput API on global system level. For DS3: http://betterds3.ciebiera.net/ for DS4: http://forums.pcsx2.net/Thread-DS4-To-XInput-Wrapper But I'm not aware if such thing exists for any DirectInput controller.

So either recommend users to use x360ce application, or simply add DirectInput API to your game.
Tom
4 posts
XInput detect Generic USB controller?
You could also use the SDL-port, as then SDL takes care of loading the correct input libraries for use with your controller for you!

In fact, this is what I'm doing, as I only have a logitech gamepad that uses DirectInput, not XInput!
I tried to use a '360-pad emulator', but it didn't want to work with my pad.. :dry:
51 posts
XInput detect Generic USB controller?
Edited by vexe on
I'm using 0 3rd party libraries (except some C library stuff like math) at the moment in my game. I'd like to keep it that way if I can :D

So I'll probably try the DirectInput approach, since this is only temporary for development only till I get an Xbox controller. When the game is shipped I'll probably just advice users to use an Xbox controller if dealing with DirectInput was a pain.
Mārtiņš Možeiko
2563 posts / 2 projects
XInput detect Generic USB controller?
More low-level approach would be to use raw input API. DirectInput actually uses raw input to talk to controllers. There are advantages and disadvantages to that.
Advantages:
1) more low-level API = more control what you do
2) event based input - you get windows message when new input is available, so less lag. No need to poll (DirectInput uses polling on separate thread = more lag).
3) one more library (DirectInput) less you depend on

Disadvantages
1) low-level API = more code to write :)
2) probably very tricky to get force-feedback to work (not sure, maybe it's not a big issue)

I have tried to use raw input to work with PS4 DualShock 4 controller. I mentioned it here: https://hero.handmadedev.org/foru...n/351-xinput-and-directinput#2296
It's pretty straight forward there and you can get force feedback working and even control led color on controller (something DirectInput cann't do).
Tom
4 posts
XInput detect Generic USB controller?
I'm using 0 3rd party libraries
Well, I suppose one could argue, that using SDL the way the SDL-Port does is more in vein of a platform than a library. B)