How to get the name of the Game Controller (Windows 10 / C ++)

I saw a lot of information on how to read game controller input using XInput, but I really want to know the name of the connected controller.

Game controller

How to find out the name of the connected controllers on the PC or, more specifically, the name of the controller from which I am reading XInput?

+4
source share
2 answers

You can do this by calling the joyGetDevCaps function , which returns a JOYCAPS containing all the information (including the name) of the connected controller.

+1
source

DirectInput . :

pDirectInput- > EnumDevices (DI8DEVCLASS_GAMECTRL, EnumJoystickCallbackStatus, & joynum, DIEDFL_ATTACHEDONLY);

: , , /GUID... , ( XInputGetState), , , , - :

BOOL CALLBACK EnumJoystickCallbackStatus(LPCDIDEVICEINSTANCE pdevinst, LPVOID pref)
{
    DWORD devtype = GET_DIDEVICE_TYPE(pdevinst->dwDevType);
    DWORD subtype = GET_DIDEVICE_SUBTYPE(pdevinst->dwDevType);

    if (devtype == DI8DEVTYPE_KEYBOARD || (devtype == DI8DEVTYPE_SUPPLEMENTAL && subtype == DI8DEVTYPESUPPLEMENTAL_UNKNOWN)) {
        return DIENUM_CONTINUE;
    }

    ULONG* pjoynum = reinterpret_cast<ULONG*>(pref);
    if (IsXInputDevice(&pdevinst->guidProduct)) {
        // loop through your known devices and see if this GUI already exists
        // we are looking for one which we don't know about yet.
        if (!found) { 
            // store GUI / Name / ... in some global controllers-array
            return DIENUM_STOP;    // done
        }
    }
    DEBUG_INFO(Debug::XDF_General, "continue");
    return DIENUM_CONTINUE;
}

, xbox, .

IsXInputDevice MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx

0

Source: https://habr.com/ru/post/1627854/


All Articles