# HG changeset patch # User StephaneLenclud # Date 1424026407 -3600 # Node ID 60bfe508372135d2da2c7f5ff486c24e1845e6e7 # Parent 687cace560d276a561fd2ee4b785f5a1bdcb593c Much improved raw input device list. diff -r 687cace560d2 -r 60bfe5083721 HidDevice.cs --- a/HidDevice.cs Sun Feb 15 18:15:41 2015 +0100 +++ b/HidDevice.cs Sun Feb 15 19:53:27 2015 +0100 @@ -79,13 +79,6 @@ //Fetch various information defining the given HID device Name = Win32.RawInput.GetDeviceName(hRawInputDevice); - //Get our HID descriptor pre-parsed data - PreParsedData = Win32.RawInput.GetPreParsedData(hRawInputDevice); - if (PreParsedData == IntPtr.Zero) - { - throw new Exception("HidDevice: GetPreParsedData failed: " + Marshal.GetLastWin32Error().ToString()); - } - //Fetch device info iInfo = new RID_DEVICE_INFO(); if (!Win32.RawInput.GetDeviceInfo(hRawInputDevice, ref iInfo)) @@ -134,6 +127,16 @@ handle.Close(); + //Get our HID descriptor pre-parsed data + PreParsedData = Win32.RawInput.GetPreParsedData(hRawInputDevice); + + if (PreParsedData == IntPtr.Zero) + { + //We are done then. + //Some devices don't have pre-parsed data. + return; + } + //Get capabilities HidStatus status = Win32.Function.HidP_GetCaps(PreParsedData, ref iCapabilities); if (status != HidStatus.HIDP_STATUS_SUCCESS) diff -r 687cace560d2 -r 60bfe5083721 HidUsageTables.cs --- a/HidUsageTables.cs Sun Feb 15 18:15:41 2015 +0100 +++ b/HidUsageTables.cs Sun Feb 15 19:53:27 2015 +0100 @@ -48,6 +48,9 @@ TerraTecRemote = 0xffcc } + /// + /// Usage Collection for usage page GenericDesktopControls. + /// public enum UsageCollectionGenericDesktop : ushort { Pointer = 0x01, @@ -61,6 +64,9 @@ SystemControl = 0x80 } + /// + /// Usage Collection for usage page Consumer. + /// public enum UsageCollectionConsumer : ushort { ConsumerControl = 0x01, diff -r 687cace560d2 -r 60bfe5083721 MainForm.Designer.cs --- a/MainForm.Designer.cs Sun Feb 15 18:15:41 2015 +0100 +++ b/MainForm.Designer.cs Sun Feb 15 19:53:27 2015 +0100 @@ -36,7 +36,7 @@ // this.labelButtonName.AutoSize = true; this.labelButtonName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.labelButtonName.Location = new System.Drawing.Point(788, 150); + this.labelButtonName.Location = new System.Drawing.Point(785, 53); this.labelButtonName.Name = "labelButtonName"; this.labelButtonName.Size = new System.Drawing.Size(103, 20); this.labelButtonName.TabIndex = 0; @@ -46,7 +46,7 @@ // this.labelDeviceName.AutoSize = true; this.labelDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.labelDeviceName.Location = new System.Drawing.Point(788, 130); + this.labelDeviceName.Location = new System.Drawing.Point(785, 33); this.labelDeviceName.Name = "labelDeviceName"; this.labelDeviceName.Size = new System.Drawing.Size(103, 20); this.labelDeviceName.TabIndex = 1; @@ -54,7 +54,7 @@ // // buttonClear // - this.buttonClear.Location = new System.Drawing.Point(816, 104); + this.buttonClear.Location = new System.Drawing.Point(813, 6); this.buttonClear.Name = "buttonClear"; this.buttonClear.Size = new System.Drawing.Size(75, 23); this.buttonClear.TabIndex = 3; diff -r 687cace560d2 -r 60bfe5083721 RawInput.cs --- a/RawInput.cs Sun Feb 15 18:15:41 2015 +0100 +++ b/RawInput.cs Sun Feb 15 19:53:27 2015 +0100 @@ -175,15 +175,66 @@ return; } - //For each our device add an node to our treeview + //For each our device add a node to our treeview foreach (RAWINPUTDEVICELIST device in ridList) { - string name=GetDeviceName(device.hDevice); - aTreeView.Nodes.Add(name, name); + Hid.HidDevice hidDevice=new Hid.HidDevice(device.hDevice); + + //Work out proper suffix for our device root node. + //That allows users to see in a glance what kind of device this is. + string suffix = ""; + if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEHID) + { + //Process usage page + if (Enum.IsDefined(typeof(Hid.UsagePage), hidDevice.Info.hid.usUsagePage)) + { + //We know this usage page, add its name + Hid.UsagePage usagePage = (Hid.UsagePage)hidDevice.Info.hid.usUsagePage; + suffix += " ( " + usagePage.ToString() + ", "; + } + else + { + //We don't know this usage page, add its value + suffix += " ( 0x" + hidDevice.Info.hid.usUsagePage.ToString("X4") + ", "; + } + + //Process usage + //We don't know this usage page, add its value + suffix += "0x" + hidDevice.Info.hid.usUsage.ToString("X4") + " )"; + } + else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD) + { + suffix = " - Keyboard"; + } + else if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEMOUSE) + { + suffix = " - Mouse"; + } + + TreeNode node = null; + if (hidDevice.Product != null && hidDevice.Product.Length > 1) + { + //Add the devices with a proper name at the top + node = aTreeView.Nodes.Insert(0, hidDevice.Name, hidDevice.Product + suffix); + } + else + { + //Add other once at the bottom + node = aTreeView.Nodes.Add(hidDevice.Name, "0x" + hidDevice.ProductId.ToString("X4") + suffix); + } + + node.Nodes.Add("Manufacturer: " + hidDevice.Manufacturer); + node.Nodes.Add("Product ID: 0x" + hidDevice.ProductId.ToString("X4")); + node.Nodes.Add("Vendor ID: 0x" + hidDevice.VendorId.ToString("X4")); + node.Nodes.Add("Version: " + hidDevice.Version); + node.Nodes.Add(hidDevice.Info.dwType.ToString()); + if (hidDevice.Info.dwType == RawInputDeviceType.RIM_TYPEHID) + { + node.Nodes.Add("UsagePage / UsageCollection: 0x" + hidDevice.Info.hid.usUsagePage.ToString("X4") + " / 0x" + hidDevice.Info.hid.usUsage.ToString("X4")); + } + + node.Nodes.Add(hidDevice.Name); } - - //TreeNode node = null; - } }