1.1 --- a/HidEvent.cs Tue Mar 03 21:07:44 2015 +0100
1.2 +++ b/HidEvent.cs Wed Mar 04 20:52:24 2015 +0100
1.3 @@ -108,12 +108,17 @@
1.4 RAWINPUT rawInput = new RAWINPUT();
1.5 if (!Win32.RawInput.GetRawInputData(aMessage.LParam, ref rawInput, ref rawInputBuffer))
1.6 {
1.7 + Debug.WriteLine("GetRawInputData failed!");
1.8 return;
1.9 }
1.10
1.11 -
1.12 - //Get various information about this HID device
1.13 - Device = new Hid.HidDevice(rawInput.header.hDevice);
1.14 + //Our device can actually be null.
1.15 + //This is notably happening for some keyboard events
1.16 + if (rawInput.header.hDevice != IntPtr.Zero)
1.17 + {
1.18 + //Get various information about this HID device
1.19 + Device = new Hid.HidDevice(rawInput.header.hDevice);
1.20 + }
1.21
1.22 if (rawInput.header.dwType == Win32.RawInputDeviceType.RIM_TYPEHID) //Check that our raw input is HID
1.23 {
1.24 @@ -204,12 +209,15 @@
1.25
1.26 Debug.WriteLine("WM_INPUT source device is Keyboard.");
1.27 // do keyboard handling...
1.28 - Debug.WriteLine("Type: " + Device.Info.keyboard.dwType.ToString());
1.29 - Debug.WriteLine("SubType: " + Device.Info.keyboard.dwSubType.ToString());
1.30 - Debug.WriteLine("Mode: " + Device.Info.keyboard.dwKeyboardMode.ToString());
1.31 - Debug.WriteLine("Number of function keys: " + Device.Info.keyboard.dwNumberOfFunctionKeys.ToString());
1.32 - Debug.WriteLine("Number of indicators: " + Device.Info.keyboard.dwNumberOfIndicators.ToString());
1.33 - Debug.WriteLine("Number of keys total: " + Device.Info.keyboard.dwNumberOfKeysTotal.ToString());
1.34 + if (Device != null)
1.35 + {
1.36 + Debug.WriteLine("Type: " + Device.Info.keyboard.dwType.ToString());
1.37 + Debug.WriteLine("SubType: " + Device.Info.keyboard.dwSubType.ToString());
1.38 + Debug.WriteLine("Mode: " + Device.Info.keyboard.dwKeyboardMode.ToString());
1.39 + Debug.WriteLine("Number of function keys: " + Device.Info.keyboard.dwNumberOfFunctionKeys.ToString());
1.40 + Debug.WriteLine("Number of indicators: " + Device.Info.keyboard.dwNumberOfIndicators.ToString());
1.41 + Debug.WriteLine("Number of keys total: " + Device.Info.keyboard.dwNumberOfKeysTotal.ToString());
1.42 + }
1.43 }
1.44 }
1.45 finally
1.46 @@ -272,7 +280,12 @@
1.47 Debug.WriteLine("==== Invalid HidEvent");
1.48 return;
1.49 }
1.50 - Device.DebugWrite();
1.51 +
1.52 + if (Device!=null)
1.53 + {
1.54 + Device.DebugWrite();
1.55 + }
1.56 +
1.57 if (IsGeneric) Debug.WriteLine("==== Generic");
1.58 if (IsKeyboard) Debug.WriteLine("==== Keyboard");
1.59 if (IsMouse) Debug.WriteLine("==== Mouse");
1.60 @@ -292,6 +305,11 @@
1.61 /// <returns></returns>
1.62 public string InputReportString()
1.63 {
1.64 + if (InputReport == null)
1.65 + {
1.66 + return "null";
1.67 + }
1.68 +
1.69 string hidDump = "";
1.70 foreach (byte b in InputReport)
1.71 {