如何在C#中与rawdata交互?

时间:2017-08-04 00:56:23

标签: c# wpf

我正试图仅从触摸屏捕获rawdata。检查HID时,我得到了很多。而且根据doc,我应该只收到0,1和2.为什么我收到3?主要目标是从触摸屏捕获并打印出所有的坐标。所有的coords意味着可能有多次接触。

[DllImport("user32.dll")]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("User32.dll")]
internal static extern uint GetRawInputData(IntPtr hRawInput, uint uiCommand, 
    IntPtr pData, ref uint pcbSize, uint cbSizeHeader);

[DllImport("User32.dll")]
internal static extern bool RegisterRawInputDevices(RAWINPUTDEVICE[] pRawInputDevice, 
    uint uiNumDevices, uint cbSize);

[DllImport("User32.dll")]
internal static extern uint GetRawInputDeviceList(IntPtr pRawInputDeviceList, 
    ref uint uiNumDevices, uint cbSize);

[DllImport("User32.dll")]
internal static extern uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, 
    IntPtr pData, ref uint pcbSize);

internal const int RIM_TYPEHID = 2;

internal const uint RIDI_DEVICENAME = 0x20000007;

private void Form1_Load(object sender, RoutedEventArgs e)
{
    uint deviceCount = 0;
    int dwSize = Marshal.SizeOf(typeof(RAWINPUTDEVICELIST));

    if (GetRawInputDeviceList(IntPtr.Zero, ref deviceCount, (uint)dwSize) == 0)
    {
        IntPtr pRawInputDeviceList = Marshal.AllocHGlobal((int)(dwSize * deviceCount));
        GetRawInputDeviceList(pRawInputDeviceList, ref deviceCount, (uint)dwSize);

        for (int i = 0; i < deviceCount; i++)
        {
            // ***here! how can I know which one is from touchscreen?***
        }
    }
    else
    {
        throw new ApplicationException("Error!");
    }
}

0 个答案:

没有答案