/// <summary> /// Gets the raw input devices attached to the system. /// </summary> /// <returns></returns> public static unsafe RawDevice[] GetRawDevices() { uint numDevices = 0; uint res = Win32.GetRawInputDeviceList(null, ref numDevices, Win32.SIZEOF_RAWINPUTDEVICELIST); if (res != 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } List <RawDevice> deviceList = new List <RawDevice>((int)numDevices); if (numDevices > 0) { RAWINPUTDEVICELIST[] rawDevices = new RAWINPUTDEVICELIST[numDevices]; res = Win32.GetRawInputDeviceList(rawDevices, ref numDevices, Win32.SIZEOF_RAWINPUTDEVICELIST); if (res != numDevices) { throw new Win32Exception(Marshal.GetLastWin32Error()); } foreach (RAWINPUTDEVICELIST rawDevice in rawDevices) { if (rawDevice.dwType == Win32.RIM_TYPEMOUSE) { // Terminal Server virtual mouse device. if (GetDeviceName(rawDevice.hDevice).Contains("RDP_MOU")) { continue; } } else if (rawDevice.dwType == Win32.RIM_TYPEKEYBOARD) { // Terminal Server virtual keyboard device. if (GetDeviceName(rawDevice.hDevice).Contains("RDP_KBD")) { continue; } } deviceList.Add(new RawDevice(rawDevice.hDevice, rawDevice.dwType)); } } return(deviceList.ToArray()); // Will never return a null reference. }
/// <summary> /// Gets the raw input devices attached to the system. /// </summary> /// <returns></returns> public static unsafe RawDevice[] GetRawDevices() { uint numDevices = 0; uint res = Win32.GetRawInputDeviceList(null, ref numDevices, Win32.SIZEOF_RAWINPUTDEVICELIST); if (res != 0) throw new Win32Exception(Marshal.GetLastWin32Error()); List<RawDevice> deviceList = new List<RawDevice>((int) numDevices); if (numDevices > 0) { RAWINPUTDEVICELIST[] rawDevices = new RAWINPUTDEVICELIST[numDevices]; res = Win32.GetRawInputDeviceList(rawDevices, ref numDevices, Win32.SIZEOF_RAWINPUTDEVICELIST); if (res != numDevices) throw new Win32Exception(Marshal.GetLastWin32Error()); foreach (RAWINPUTDEVICELIST rawDevice in rawDevices) { if (rawDevice.dwType == Win32.RIM_TYPEMOUSE) { // Terminal Server virtual mouse device. if (GetDeviceName(rawDevice.hDevice).Contains("RDP_MOU")) continue; } else if (rawDevice.dwType == Win32.RIM_TYPEKEYBOARD) { // Terminal Server virtual keyboard device. if (GetDeviceName(rawDevice.hDevice).Contains("RDP_KBD")) continue; } deviceList.Add(new RawDevice(rawDevice.hDevice, rawDevice.dwType)); } } return deviceList.ToArray(); // Will never return a null reference. }