Search code examples
windowswinapitouch

(How) can I obtain additional information about `TOUCHINPUT` source device using `hSource` handle?


I am hooking windows touch events on my c# windows application in order to allow input from multiple touchscreens. My problem is that not only do I want to be able to differentiate between different devices at runtime, I also want to know what input a device provided in previous system boot sessions. And the trouble is that system seems to give unique hSource handles to each device while booting.

It is said in Microsoft docs that hSource is

A device handle for the source input device. Each device is given a unique provider at run time by the touch input provider.

That inspires a thought that hSource is no more than just unique identifier. But I am still wondering if there is a way to obtain additional info about device with given id, preferably such that is unique for each device and is consistent across different system boot sessions.

I've already tried to treat this handle as a file handle and use GetFileInformationByHandle, but surprisingly (that's self-ironic) with no success.

Any help is appreciated, especially negative (i.e. you right, is no way, at least with windows touch api).


Solution

  • can I obtain additional information about TOUCHINPUT source device using hSource handle?

    You can use GetRawInputDeviceInfo to obtain additional information like this:

    RID_DEVICE_INFO info;
    ZeroMemory(&info, sizeof(RID_DEVICE_INFO));
    UINT size = 0;
    if (GetRawInputDeviceInfo(touchInput.hSource, RIDI_DEVICEINFO, &info, &size)) {
    }
    else {
        DWORD err = GetLastError();
    }
    

    Refer to TOUCHINPUT structure and GetRawInputDeviceInfo.