示例#1
0
        public RawInputDevice(Win32.RawInputDeviceList rawInputDeviceList)
        {
            this._rawInputDeviceList = rawInputDeviceList;

            _deviceName =
                GetDeviceName(this._rawInputDeviceList.DeviceHandle);

            _deviceInfo =
                GetDeviceInfo(this._rawInputDeviceList.DeviceHandle);
        }
示例#2
0
文件: b.cs 项目: xyandro/NeoEdit
		static string FindDevice()
		{
			int numDevices = 0;
			var ridlSize = Marshal.SizeOf(typeof(Win32.RawInputDeviceList));
			Win32.GetRawInputDeviceList(null, ref numDevices, ridlSize);

			var deviceList = new Win32.RawInputDeviceList[numDevices];
			Win32.GetRawInputDeviceList(deviceList, ref numDevices, ridlSize);

			foreach (var device in deviceList)
			{
				var size = 0;
				Win32.GetRawInputDeviceInfoW(device.hDevice, Win32.RIDI_DEVICENAME, null, ref size);
				if (size <= 1) // Only null terminator
					continue;

				var nameBuf = new byte[size * 2]; // Size is number of C wchars
				Win32.GetRawInputDeviceInfoW(device.hDevice, Win32.RIDI_DEVICENAME, nameBuf, ref size);
				var name = Encoding.Unicode.GetString(nameBuf, 0, size * 2 - 2); // Strip null

				if (name.StartsWith(@"\\?\HID#VID_11FA&"))
				{
					if (device.Type == Win32.RawInputDeviceType.KEYBOARD)
						SwitchKeyboardsToHidNative(device.hDevice);
					return name;
				}
			}
			throw new DeviceNotFoundException("Unable to find device");
		}