locked
HID HidP_GetButtonCaps and Windows.Devices.HumanInterfaceDevice RRS feed

  • Question

  • Hey, 

    with the new HID API in Windows 8.1, I can finally connect to gamepad which is not XBox Controller, and I can get raw data from incoming input, and that's great ! Thank you for that.

    So I slightly modified Custom HID Device Access Sample (http://code.msdn.microsoft.com/windowsapps/Custom-HID-Device-Access-40c3aa8f) from Windows 8.1 samples, to accept other HID devices which are not SuperMutt devices.

    But there is a slight problem, to be able to parse data, you have to know usagePage & usageId, which you would pass to.

    				HidDevice device;
    				device.GetNumericControlDescriptions(HidReportType.Input, ?, ?);
    				..
    				HidNumericControlDescription desc;
    				HidInputReport inputReport;
    				HidNumericControl ctrl = inputReport.GetNumericControlByDescription(desc);

    In traditional Win32 API, you would get those values from HidP_GetButtonCaps (http://msdn.microsoft.com/en-us/library/windows/hardware/ff539707(v=vs.85).aspx), is there a similar function API in  Windows.Devices.HumanInterfaceDevice ?

    Thank you

    Thursday, February 13, 2014 8:06 AM

Answers

  • And one more updated, for buttons which return "True" or "False", it's better to write like this:

    				HidInputReport inputReport;
    				IReadOnlyList<HidBooleanControl> activeBoolCtrls = inputReport.ActivatedBooleanControls;
    
    

    Instead of :

    				inputReport.GetBooleanControlByDescription(<description>);

    That way results are consistent, because with GetBooleanControlByDescription, you seem to do additional preprocessing.

    • Marked as answer by Anne Jing Thursday, February 20, 2014 9:15 AM
    Thursday, February 13, 2014 11:09 AM

All replies

  • Answering to my own thread, it seems you can do something like this:

    					HidDevice device;
    					for (ushort usagePage = 0; usagePage < 255; usagePage++)
    					{
    						for (ushort usageId = 0; usageId < 255; usageId++)
    						{
    							IReadOnlyList<HidBooleanControlDescription> boolDescs = device.GetBooleanControlDescriptions(HidReportType.Input, usagePage, usageId);
    							if (boolDescs.Count > 0)
    							{
    								mappedBoolDescs[new KeyValuePair<ushort, ushort>(usagePage, usageId)] = boolDescs;
    							}
    
    							IReadOnlyList<HidNumericControlDescription> numDescs = device.GetNumericControlDescriptions(HidReportType.Input, usagePage, usageId);
    							if (numDescs.Count > 0)
    							{
    								mappedDescs[new KeyValuePair<ushort, ushort>(usagePage, usageId)] = numDescs;
    							}
    						}
    					}

    While this is not pretty, it seems to work, and using these descriptions I can get values from joystick, both which are simple booleans or numerical values.

    Thursday, February 13, 2014 10:49 AM
  • And one more updated, for buttons which return "True" or "False", it's better to write like this:

    				HidInputReport inputReport;
    				IReadOnlyList<HidBooleanControl> activeBoolCtrls = inputReport.ActivatedBooleanControls;
    
    

    Instead of :

    				inputReport.GetBooleanControlByDescription(<description>);

    That way results are consistent, because with GetBooleanControlByDescription, you seem to do additional preprocessing.

    • Marked as answer by Anne Jing Thursday, February 20, 2014 9:15 AM
    Thursday, February 13, 2014 11:09 AM