public static bool Exists() { uint deviceListCount = 0; uint rawInputDeviceListSize = (uint)Marshal.SizeOf <RAWINPUTDEVICELIST>(); if (GetRawInputDeviceList( null, ref deviceListCount, rawInputDeviceListSize) != 0) { return(false); } var devices = new RAWINPUTDEVICELIST[deviceListCount]; if (GetRawInputDeviceList( devices, ref deviceListCount, rawInputDeviceListSize) != deviceListCount) { return(false); } foreach (var device in devices.Where(x => x.dwType == RIM_TYPEHID)) { uint deviceInfoSize = 0; if (GetRawInputDeviceInfo( device.hDevice, RIDI_DEVICEINFO, IntPtr.Zero, ref deviceInfoSize) != 0) { continue; } var deviceInfo = new RID_DEVICE_INFO { cbSize = deviceInfoSize }; if (GetRawInputDeviceInfo( device.hDevice, RIDI_DEVICEINFO, ref deviceInfo, ref deviceInfoSize) == unchecked ((uint)-1)) { continue; } if ((deviceInfo.hid.usUsagePage == TouchpadUsagePage) && (deviceInfo.hid.usUsage == TouchpadUsage)) { return(true); } } return(false); }
private static RAWINPUTDEVICELIST[] EnumerateDevices(RawInputDeviceType ty) { RAWINPUTDEVICELIST[] retVal = null; uint count = 0; int res = Function.GetRawInputDeviceList(retVal, ref count, (uint)Marshal.SizeOf(typeof(RAWINPUTDEVICELIST))); retVal = new RAWINPUTDEVICELIST[count]; res = Function.GetRawInputDeviceList(retVal, ref count, (uint)Marshal.SizeOf(typeof(RAWINPUTDEVICELIST))); return(retVal.Where(x => x.dwType == ty).ToArray()); }
private IEnumerable <RAWINPUTDEVICELIST> GetRawInputDevices(uint type) { uint deviceCount = 0; uint dwSize = (uint)Marshal.SizeOf(typeof(RAWINPUTDEVICELIST)); uint retValue = GetRawInputDeviceList(null, ref deviceCount, dwSize); if (0 != retValue) { return(null); } RAWINPUTDEVICELIST[] deviceList = new RAWINPUTDEVICELIST[deviceCount]; retValue = GetRawInputDeviceList(deviceList, ref deviceCount, dwSize); return(deviceList.Where(ridl => ridl.dwType == type)); }