/// <summary> /// Retrieves the GUID of the stylus property associated with the usage page and usage ids /// within the HID specification. /// </summary> /// <param name="page">The usage page id of the HID specification</param> /// <param name="usage">The usage id of the HID specification</param> /// <returns> /// If known, the GUID associated with the usagePageId and usageId. /// If not known, GUID.Empty /// </returns> internal static Guid GetKnownGuid(HidUsagePage page, HidUsage usage) { Guid result = Guid.Empty; Dictionary <HidUsage, Guid> pageMap = null; if (_hidToGuidMap.TryGetValue(page, out pageMap)) { pageMap.TryGetValue(usage, out result); } return(result); }
protected override void ParseHw() { base.ParseHw(); string[] v; // this is how we determine the HID class of the device. I've found this to be a very reliable method. foreach (string hw in _HardwareIds) { int i = hw.IndexOf("HID_DEVICE_UP:"); if (i >= 0) { v = TextTools.Split(hw.Substring(i), ":"); if (v.Length > 1) { ushort hp; if (ushort.TryParse(v[1].Replace("_U", ""), System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.CurrentCulture.NumberFormat, out hp)) { _HidPage = (HidUsagePage)(hp); if ((int)_HidPage > 0xFF) { _HidPage = HidUsagePage.Reserved; if (v.Length > 2) { if (ushort.TryParse(v[1].Replace("_U", ""), System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.CurrentCulture.NumberFormat, out hp)) { _HidPage = (HidUsagePage)(hp); if ((int)_HidPage > 0xFF) { _HidPage = HidUsagePage.Reserved; } } } return; } else { return; } } } } } }
/// <summary> /// Enumerates all HID devices in a specific HID class. /// </summary> /// <param name="u">The HID usage page type devices to return.</param> /// <returns>An array of HidDeviceInfo objects.</returns> /// <remarks></remarks> public static HidDeviceInfo[] HidDevicesByUsage(HidUsagePage u) { var devs = DeviceEnum.EnumerateDevices <HidDeviceInfo>(DevProp.GUID_DEVINTERFACE_HID); HidDeviceInfo[] devOut = null; int c = 0; foreach (var blurb in devs) { if (blurb.HidUsagePage == u || u == HidUsagePage.Undefined) { Array.Resize(ref devOut, c + 1); devOut[c] = blurb; c += 1; } } return(devOut); }