rawinput-sharp
rawinput-sharp copied to clipboard
ArgumentException at RawInputDigitizerContact constructor with TouchPad
Thank you for great library! It is really useful to get inputs from HID devices.
I have tested it to parse inputs from Precision TouchPad (PTP) and encountered System.ArgumentException (HResult=0x80070057
Message=An item with the same key has already been added.) at RawInputDigitizerContact constructor when a window receives WM_INPUT message. They are fired at following two Enumerable.ToDictionary methods.
https://github.com/mfakane/rawinput-sharp/blob/fd5c60006c19bed997594bee6315f44aaabab73f/RawInput.Sharp/RawInputDigitizerContact.cs#L38-L39
This exception is relatively common in Enumerable.ToDictionary method when there are duplicate keys. It is not difficult to avoid this exception and I will be happy to send PR to fix this issue.
Before start working, I would like to hear your view on this issue especially whether the first value or the last value is to be preserved. I have no strong view on this selection.
Hi, I've stumbled across this problem in our software and agree with @emoacht's diagnosis.
It seems that Windows sometimes bundles several touch messages into one hid report, so there are several entries with the same UsageAndPage which cause the ToDictionary to throw.
Currently we are ignoring duplicate entries, but this means we are discarding valid touch input, which isn't ideal.
This is a quickwatch of RawInputDigitizerContact.cs for the contactButtonStates showing multiple entries for the same usage page.
contactCount is calculated to be 1 because the linq evaluates to null.
👍