Reputation: 1729
I read article Using Raw Input from C# to handle multiple keyboards and download the source. It works when I run it in Windows 7, but failed when I run it in Windows 8.
I've got "Object reference not set to an instance of an object." error on
string deviceClass = (string)OurKey.GetValue("Class");
if (deviceClass.ToUpper().Equals("KEYBOARD"))
I placed breakpoint at string deviceClass
and see the value is null. If you look at the downloaded source the value is obtained from the registry. Is there any difference between Windows 7 and Windows 8 to obtain this value? How do I solve this?
Upvotes: 0
Views: 2340
Reputation: 1
This is due to the Class REG_SZ value no longer used in Windows 8 and higher.
You can use the Service value instead but make sure to search for the appropriate data kbdhid
string deviceClass = (string)OurKey.GetValue("Service");
if (deviceClass.Equals("kbdhid"))
Upvotes: 0
Reputation: 175766
That code expects a Class
value to be present in the appropriate HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\
key, on my Windows 8 machine none of the entries have this key so you will get the behaviour you describe.
That is a poor way to get the class even if the key did exist; instead p/invoke GetRawInputDeviceInfo()
for the device class.
Upvotes: 2