Search code examples
windowsdirectxenumerationdirectinput

DirectInput analogue joystick range


I use DirectInput to handle input devices, I enumerate devices and elements on each device.

When using the analogue sticks on my game pad, they report values in the range 0-65535. Is this always the case for all types of absolute axis?

If not: is there any way to find out the range of an DX8 input element's DIDEVICEOBJECTDATA::dwData (enumerated with DIDFT_ABSAXIS)? The only other option I can think of is to use some home made internal calibration inside my app, and that sound too '80s to be true.


Solution

  • As Goz so sweetly put it, I did the following, which worked:

    dev->EnumObjects(EnumElementsCallback, 0, DIDFT_ALL);
    
    BOOL CALLBACK EnumElementsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID)
    {
        if ((dev->dwType & DIDFT_ABSAXIS) != 0)
        {
            DIPROPRANGE range;
            range.diph.dwSize = sizeof(DIPROPRANGE);
            range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
            range.diph.dwHow = DIPH_BYID;
            range.diph.dwObj = dev->dwType;
            if (lDevice->mDIDevice->GetProperty(DIPROP_RANGE, &range.diph) == DI_OK)
            {
                ... = range.lMin;
                ... = range.lMax;
            }
        }
    }