SOLVED Problem detecting gamepads on win10 64bit

Xennroth

Member
Hello.

i am trying to add gamepad support for my project, but gms cant recognize any gamepads on windows10 for some reason.
i tested 3 different pads, they work perfectly on other software\games, but not on gms.

any ideas?

test code:
GML:
global.gamepad_index = 0; // this is supposed to be the first gamepad that is found from system
for (var i = 0; i < gamepad_get_device_count(); i++;)
{
    if(global.gamepad_index == 0)
    {
        if(gamepad_is_connected(i)){global.gamepad_index=i;}
    }
    else // for debugging, cant recognize any gamepads on windows
        show_message("gamepad_index: "+ string(global.gamepad_index));
}


SOLVED.
Solution: https://forum.yoyogames.com/index.p...ing-gamepads-on-win10-64bit.85640/post-511982
 
Last edited:

Xennroth

Member
btw, i do know that

global.gamepad_index = 0;
should be
global.gamepad_index = -1;
when initialized since pads start from 0.

the code i posted is just example. but that is not the problem here, just cant detect any pads on win10.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Don't use "gamepad_get_device_count()" to start with. It may detect 2 gamepads, but their "slots" could be 4 and 5, so that loop will never find them. First, I'd use the ASYNC system event for gamepads to detect them rather than try and do it manually like this, as that event will fire once at the start of the game, and then every time a gamepad is detected or removed. This is especially relevant on windows where DirectX gamepads are in alots 0 - 3 and direct input pads are in slots 4+. https://manual-en.yoyogames.com/#t=...ce/Game_Input/GamePad_Input/Gamepad_Input.htm

Note that while the information on that page is correct, it does have one slight error in that gamepad slots are not capped at 11 and you could have a gamepad slot that is higher than that.
 

Xennroth

Member
Note that while the information on that page is correct, it does have one slight error in that gamepad slots are not capped at 11 and you could have a gamepad slot that is higher than that.
do you know if there is a specific cap on windows builds of gms projects?
 

kburkhart84

Firehammer Games
From what I've known, on Windows, the device IDs are always only 0 - 3 for XInput and 4 - 11 for DInput. I've never seen any IDs higher than that on Windows despite having that many devices connected. However, on Linux, it seems that device IDs start at 20. And on Android, they start at 1. I don't even know what they do on Mac. I've sent a request to Yoyo in the past for them to better document these differences and even better if they would make it the same IDs on all platforms.
 

Xennroth

Member
here is the solution for future reference:

create event:
GML:
global.gamepad_index = -1;
async - system event:
GML:
/* set gamepad_index as the first gamepad that is found from system */
if((ds_map_find_value(async_load, "pad_index")) && (global.gamepad_index == -1))
{
    global.gamepad_index = ds_map_find_value(async_load, "pad_index");
}
on player step event:
GML:
key_check_up    = gamepad_axis_value(global.gamepad_index,1)<0;
key_check_down  = gamepad_axis_value(global.gamepad_index,1)>0;
key_check_left  = gamepad_axis_value(global.gamepad_index,0)<0;
key_check_right = gamepad_axis_value(global.gamepad_index,0)>0;
 

kburkhart84

Firehammer Games
/* set gamepad_index as the first gamepad that is found from system */
Maybe not now, but in the future you may want to consider letting the player choose a different gamepad. It would be something in the options menu. I personally dislike a game that forces me to a certain gamepad, as I have a few of them and different games work better with different ones. I've also heard of false positives being detected as gamepads and so if someone has one that happens to come up first they will be stuck.
 

Xennroth

Member
Maybe not now, but in the future you may want to consider letting the player choose a different gamepad. It would be something in the options menu. I personally dislike a game that forces me to a certain gamepad, as I have a few of them and different games work better with different ones. I've also heard of false positives being detected as gamepads and so if someone has one that happens to come up first they will be stuck.
very true.

i will add it later when i start to code the configuration tabs for the game, just basic support for now :)
 
Top