List Human Interface Devices using C#

Asked

Viewed 728 times

1

I am facing difficulty in figuring out how to list and access a device on PC, remembering that although the entry is USB it is recognized as a HID human interface device type mouse or keyboard.

Well I’ve seen several and several sites the most promising I found would be using a select with ManagementObjectSearcher then access the class win32 but I did not find any option in it that returns me Hids or at least I didn’t find the right shape.

1 answer

1

For example:

If it’s to print the name of all USB locations of your computer would be:

System.Management.ManagementClass usbClass = new ManagementClass("Win32_USBHub");
System.Management.ManagementObjectCollection usbCollection = usbClass.GetInstances();
foreach (ManagementObject usb in usbCollection)
{

    System.Console.WriteLine("{0} {1} {2}", 
        "HID".Contains((string)usb.GetPropertyValue("PNPDeviceID")), 
        usb.GetPropertyValue("name"),
        usb.GetPropertyValue("PNPDeviceID"));
}
  • so that had already seen and managed to implement.. however need to list human interface devices if enter the device manager you will see that are different the human interface devices of the usb, although both are usb input

  • @Tamires, I made an edit, please test this code and make sure it comes out in some of the lines true or false (at the beginning), if true is what you are looking for! please stand by?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.