• Advertisement
Sign in to follow this  

[DirectInput] Get gamepad button name

This topic is 687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I'm wondering if there is any reliable way of obtaining the actual name of a button for display from a gamepad in DirectInput?

 

I tried using EnumObjects:

 

BOOL __stdcall enumButtonsCallback(LPCDIDEVICEOBJECTINSTANCE lpDDoi, LPVOID pvRef)
{
    auto pGamepad = (Gamepad*)pvRef;
    pGamepad->AddButtonName(lpDDoi->tszName);

    return DIENUM_CONTINUE;
}

m_pDevice->EnumObjects(enumButtonsCallback, this, DIDFT_BUTTON);

 

However this gives me only generic names like "Button0" to "ButtonX" on every gamepad (even for an XBox-Controller, I'm using XInput for those now anyways but still). What I would like to do is get a description of the actual button, like "A", "Start", "RB", ... to actually show to the user.

 

Is there any way for doing this? In XInput this is easy because buttons meanings are fixed, but in DirectInput the meaning of the Button with ID "5" can change depending on the pad.

 

If there is no such way, what do you show your users for gamepad key bindings? I want to do a graphical menu for setting key bindings, which should give the user a good idea what is actually bound without having to try out everything to get to know what "Button 5" actually stands for...

Share this post


Link to post
Share on other sites
Advertisement

'Fraid not. One of the reasons DInput was deprecated is that gamepads and other HIDs are not standardized. If you're concerned about this kind of conflict the best thing to do is to offer custom key-binding support to the user. If you're exclusively concerned with gamepads then consider using XInput instead, as it has become something of a de-facto standard for gamepads on Windows.

Share this post


Link to post
Share on other sites
'Fraid not. One of the reasons DInput was deprecated is that gamepads and other HIDs are not standardized. If you're concerned about this kind of conflict the best thing to do is to offer custom key-binding support to the user. If you're exclusively concerned with gamepads then consider using XInput instead, as it has become something of a de-facto standard for gamepads on Windows.

 

Sure, just implemented a custom keybind menu today. The problem which I was referring to is still present though, because now I still can only display eigther cryptic key names ("Button1", ...) or some that could be wrong (if I assume button 5 is "start" that might be wrong for some pads). So in case of custom key-binding GUIs, what do you usually display?

 

I strangely cannot recall any game that does that, but is it really common to show gamepad bindings as "Button0"-"ButtonX"? This pretty much means any user will have to manually rebind all buttons, as nobody will have any idea which label stands for which gamepad button. For example: My gamepad has buttons actually label 1-4, than start/select which are 9/10, 4 should-buttons 5,6,7,8. Now look at the attached screenshot ("Taste" is german for button), and how confusing that is). Theres gotta be at least something less confusing than that. Do I just "quess" which buttons could mean which, and risk that they might be wrong (like "Start" actually being "A" on some gamepads")? Or any other idea?

 

EDIT: Also, I'm using XInput, but since old devices do not support it (and I certainly want to play my SNES-style game with my SNES-controller adapter!), I have no choice but to support DirectInput at least as a fallback.

Edited by Juliean

Share this post


Link to post
Share on other sites

but is it really common to show gamepad bindings as "Button0"-"ButtonX"?


Yes, apart from XInput it's usually just numbered buttons. It's not hard for the user to figure out during key mapping. If you push a button and it says "Button 1" then chances are you're pushing button 1. There's really no standard to these things, so trying to predict what's what will only piss off the people that you guessed wrong for.

 

If you're interested in a specific controller then you can just have an option to label the buttons for that controller specifically. For example, some XInput games have an option for "Dualshock 3" that changes the XBox button labels to their SCP Driver equivalents. (Usually it's just a matter of loading a different texture for the button images.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement