How to tell a controller is Xinput or Dinput?

RangerX

Member
I am asking this because I want to detect what type of controllers the player uses. I could check either its a Xinput of Dinput or again, if those controllers always connect at a precise range of "pad index", I would also be able to tell.

PLEASE:
- I know I can make a button configuration menu. This doesn't answer my question still.
- I know most new generic gamepad will come up as Xinput. This doesn't answer my question either.

Xinput and Dinput have different face buttons it seems. So I wonder how people do it when they offer different controller schemes for their player or again, when they simply want to automatically move the buttons around in order to have the same config on both types. And why is this not in the manual? seriously.
 

rIKmAN

Member
X Input devices will always register as index 0-3. Direct Input devices will be from 4-11.
Not sure if it's been fixed, but there was/is a bug of some sort where a pad will register as both index 0 and index 4 in certain circumstances.

Do a forum search RangerX if this happens to you, as I remember seeing it discussed on here before.
 
I have seen that bug before. I had actually reported it quite a while ago. It was supposed to be fixed. Unfortunately, I no longer own an Xinput device to check this anymore.
 

RangerX

Member
X Input devices will always register as index 0-3. Direct Input devices will be from 4-11.
I don't want to be an ass but... you tested that or can we have a confirmed source?
I sure don't have enough controllers to test this. :(

EDIT:
My Xbox 360 controller indeed shows up as 0.
My PS4 controller showed up as 4.
 
Last edited:

rIKmAN

Member
I don't want to be an ass but... you tested that or can we have a confirmed source?
I sure don't have enough controllers to test this. :(
It's in the manual...
https://docs2.yoyogames.com/source/...l_reference/controls/gamepad input/index.html
The gamepad "slots" are indexed from 0 with slots 0 - 3 inclusive being only for Xinput gamepads, ie: Xbox360 controllers and compatibles. However you can also check slots 4 - 11 inclusive for DirectInput gamepads, which means you can detect many other models of controller when connected through these slots.
 

RangerX

Member
Jeez, I read that over and over and couldn't see it. :confused:

Something is not fun though. They say "A" comes as "X" on PS controllers and all that. The face buttons doesn't come out like that for me with my PS4 controller. Only Y is Triangle. Rest is all mess up.
 
Yeah, RangerX, I have a really crappy non-brand name controller that is a D-Input and the damn button configurations change for nearly every game I play with it (not too mention 3/4 of multiplayer games don't support the damn thing). I'm definitely going to make it supported in my game (so my son and I can play it) but I wish that the overall system for controllers was a bit smoother to work with.
 

hogwater

Member
Xbox 360 and Xbox One controllers show up in slots 0-3, I have tested this. Also, if an xbox controller is plugged in before the game is run, it only shows up in slot 0. If it is plugged in after the game has started (or is unplugged and plugged back in) it will show up in both slots 0 and 4 That was the behavior in my game with GMS 1.4.

Also, you are correct that the PS face buttons do not match the Xbox ones. The manual description is correct for Xbox only. However, all the PS controllers I own have the same layout, so you can create one layout for Xbox and another for PS (DirectInput).

The real 💩💩💩💩 you is that controllers that are not PS, but are DirectInput will do whatever they want. For example the 8BitDo SFC pad I have is completely different and basically unusable until I make a button mapping option.

For Windows games, I don't know if there is a way to truly "solve" this. The best idea I had was one layout for XInput, one for DInput (based on PS). Any other controller is screwed without button mapping options.
 

RangerX

Member
Xbox 360 and Xbox One controllers show up in slots 0-3, I have tested this. Also, if an xbox controller is plugged in before the game is run, it only shows up in slot 0. If it is plugged in after the game has started (or is unplugged and plugged back in) it will show up in both slots 0 and 4 That was the behavior in my game with GMS 1.4.

Also, you are correct that the PS face buttons do not match the Xbox ones. The manual description is correct for Xbox only. However, all the PS controllers I own have the same layout, so you can create one layout for Xbox and another for PS (DirectInput).

The real **** you is that controllers that are not PS, but are DirectInput will do whatever they want. For example the 8BitDo SFC pad I have is completely different and basically unusable until I make a button mapping option.

For Windows games, I don't know if there is a way to truly "solve" this. The best idea I had was one layout for XInput, one for DInput (based on PS). Any other controller is screwed without button mapping options.
Interesting.
I came basically to the same conclusion as you. Supporting Xinput as Xbox controllers and Dinput as PS controllers. I suspect most generic controllers are made like Xbox and most gamers that will play with a controllers are probably gamers that will play with their controllers from consoles. This gen there's way more PS4s than anything Xbox on the market so it should be good. I don't feel like truly supporting generic controllers that aren't following either of the models. My problem comes from the fact I like to have the buttons' names on screen and that we can't tell for sure what controller is what by their description. So yeah, Xbox and PS namings will be supported (Xinput and Dinput) but the rest will sadly be put aside of they will play the game as whatever their bastard controller comes as.
 

Mick

Member
I think it's better to use gamepad_get_button_count() for directinput gamepads in slots 4+ and check for button presses >=0 and <button_count instead of using the gp_constants). You can create an arrary of names for the buttons yourself so they are correct for ps3/4 pads (filling the rest of the array with Button 12, Button 13 etc.)

Edit: reading your last message you basically said the same thing...
 

TrunX

Member
What you could also do is to check the start button of all slots (the XInput and DInput ones) in a for-loop during the start screen and depending on which controller presses start you know what kind of controller it is.
 

RangerX

Member
What you could also do is to check the start button of all slots (the XInput and DInput ones) in a for-loop during the start screen and depending on which controller presses start you know what kind of controller it is.
Yeah but it was more to know what type of controller it is (Xinput or Dinput) so now my problem is solved. I simply consider Xinput Xbox controllers and Dinput PS controllers and call it a day.
 

RangerX

Member
Yes, but it cannot give a good description. Many controllers are returning the same name. This is why I cut the whole thing at 2 controllers. 360 and PS4.
Its because in a perfect world I would like to have all the naming in-game. But right now its unthinkable so my "less worse solution" is that: I will have Xbox naming and PS naming. If someone is playing with a generic controller that doesn't follow any of the 2 models then, too bad. A majority of players will play with and Xbox or PS controller I think.
 
W

Wraithious

Guest
Yes, but it cannot give a good description. Many controllers are returning the same name.
do you mean that some generic controllers return Xbox 360 Controller (XInput STANDARD GAMEPAD) or PLAYSTATION(R)3 Controller when they are checked with gamepad_get_description(device) ? That's really weird. I was going to suggest simply parsing that string and look for xbox or playstation and set your mapping variables accordingly, and if neither is found bring up a mapping screen for the player,

BUT if that really is the case with generic pads using those strings as their description there is another way, when a gamepad is detected you can show a message for the player to "press controller's bottom face button" (and/or an image showing which button you mean) and then simply check what that button did, and then you will know how to proceed from there and either set up the mappings or bring up the mapping screen for the player depending on the result.
 

RangerX

Member
You solution is interesting too. Although I wanted to avoid a full control mapping for controllers.
I didn't test the namings much, I just collected info left and right. Apparently that many controllers return the same strings. So I suspect I might not be able to differenciate a PS-like controller from Logitek than an Xbox-like controller from Logitek maybe. I might do further testing down the road though. This is the type of things that annoys me you know, when I see something in my game that could theorically be more user friendly. Always feel like making it better.
My real problem is that I like button namings. I want my game to say "Press X to jump" and "Press A to jump". Since I might not be able to differenciate between certain generic controllers, its becomes annoying.
 

Gamebot

Member
Does the constants:

for (i = 32769; i < 32789; i++) {
if gamepad_button_check_pressed(argument0,j) {
return = j;
}
}

Not work with all gamepads?

Thought you could use numbers each time to do something instead of actually mapping.
 

RangerX

Member
Does the constants:

for (i = 32769; i < 32789; i++) {
if gamepad_button_check_pressed(argument0,j) {
return = j;
}
}

Not work with all gamepads?

Thought you could use numbers each time to do something instead of actually mapping.
Most probably not. First button maybe get the same id number in GameMaker, who knows. But there's nothing preventing a controller for having X instead of A as the first button. Am pretty sure stuff like that happens.
 

Gamebot

Member
Good point. Now that I'm thinking about it yeah that would make sense. For some reason I think I confused the constants for game button numbers themselves. Crap!
 
Last edited:
W

Wraithious

Guest
The descriptions can't be relied on. My PS4 pad returns "wireless controller" for example. LOWERCASE
I see your point on returning "wireless controller" but if you were parsing a string for a certain word you natrually would convert the string to all lower or upper case first. (Theres functions for doing that, check the manual) Then parse the string to look for the word
 

hogwater

Member
I see your point on returning "wireless controller" but if you were parsing a string for a certain word you natrually would convert the string to all lower or upper case first. (Theres functions for doing that, check the manual) Then parse the string to look for the word
I meant that in a "Windows couldn't even put in the effort to drop a capital letter or two" kind of way, rather than lowercase actually being a problem.
 

nesrocks

Member
My logitech F310 returns "Xbox 360 Controller (XInput STANDARD GAMEPAD)", but that's ok because its buttons are on the same places as the xbox controller.
 
Top