1.1 --- a/HidEvent.cs Thu Mar 05 10:12:37 2015 +0100
1.2 +++ b/HidEvent.cs Sun Mar 15 09:53:37 2015 +0100
1.3 @@ -22,6 +22,9 @@
1.4 public bool IsBackground { get { return !IsForeground; } }
1.5 public bool IsMouse { get; private set; }
1.6 public bool IsKeyboard { get; private set; }
1.7 + /// <summary>
1.8 + /// If this not a mouse or keyboard event then it's a generic HID event.
1.9 + /// </summary>
1.10 public bool IsGeneric { get; private set; }
1.11 public bool IsButtonDown { get { return Usages.Count == 1 && Usages[0] != 0; } }
1.12 public bool IsButtonUp { get { return Usages.Count == 0; } }
1.13 @@ -29,6 +32,8 @@
1.14 public uint RepeatCount { get; private set; }
1.15
1.16 public HidDevice Device { get; private set; }
1.17 + public RAWINPUT RawInput { get {return iRawInput;} }
1.18 + private RAWINPUT iRawInput;
1.19
1.20 public ushort UsagePage { get; private set; }
1.21 public ushort UsageCollection { get; private set; }
1.22 @@ -76,7 +81,6 @@
1.23 IsKeyboard = false;
1.24 IsGeneric = false;
1.25
1.26 -
1.27 Time = DateTime.Now;
1.28 OriginalTime = DateTime.Now;
1.29 Timer = new System.Timers.Timer();
1.30 @@ -105,8 +109,8 @@
1.31 try
1.32 {
1.33 //Fetch raw input
1.34 - RAWINPUT rawInput = new RAWINPUT();
1.35 - if (!Win32.RawInput.GetRawInputData(aMessage.LParam, ref rawInput, ref rawInputBuffer))
1.36 + iRawInput = new RAWINPUT();
1.37 + if (!Win32.RawInput.GetRawInputData(aMessage.LParam, ref iRawInput, ref rawInputBuffer))
1.38 {
1.39 Debug.WriteLine("GetRawInputData failed!");
1.40 return;
1.41 @@ -114,13 +118,13 @@
1.42
1.43 //Our device can actually be null.
1.44 //This is notably happening for some keyboard events
1.45 - if (rawInput.header.hDevice != IntPtr.Zero)
1.46 + if (RawInput.header.hDevice != IntPtr.Zero)
1.47 {
1.48 //Get various information about this HID device
1.49 - Device = new Hid.HidDevice(rawInput.header.hDevice);
1.50 + Device = new Hid.HidDevice(RawInput.header.hDevice);
1.51 }
1.52
1.53 - if (rawInput.header.dwType == Win32.RawInputDeviceType.RIM_TYPEHID) //Check that our raw input is HID
1.54 + if (RawInput.header.dwType == Win32.RawInputDeviceType.RIM_TYPEHID) //Check that our raw input is HID
1.55 {
1.56 IsGeneric = true;
1.57
1.58 @@ -130,31 +134,31 @@
1.59 UsagePage = Device.Info.hid.usUsagePage;
1.60 UsageCollection = Device.Info.hid.usUsage;
1.61
1.62 - if (!(rawInput.hid.dwSizeHid > 1 //Make sure our HID msg size more than 1. In fact the first ushort is irrelevant to us for now
1.63 - && rawInput.hid.dwCount > 0)) //Check that we have at least one HID msg
1.64 + if (!(RawInput.hid.dwSizeHid > 1 //Make sure our HID msg size more than 1. In fact the first ushort is irrelevant to us for now
1.65 + && RawInput.hid.dwCount > 0)) //Check that we have at least one HID msg
1.66 {
1.67 return;
1.68 }
1.69
1.70 //Allocate a buffer for one HID input
1.71 - InputReport = new byte[rawInput.hid.dwSizeHid];
1.72 + InputReport = new byte[RawInput.hid.dwSizeHid];
1.73
1.74 - Debug.WriteLine("Raw input contains " + rawInput.hid.dwCount + " HID input report(s)");
1.75 + Debug.WriteLine("Raw input contains " + RawInput.hid.dwCount + " HID input report(s)");
1.76
1.77 //For each HID input report in our raw input
1.78 - for (int i = 0; i < rawInput.hid.dwCount; i++)
1.79 + for (int i = 0; i < RawInput.hid.dwCount; i++)
1.80 {
1.81 //Compute the address from which to copy our HID input
1.82 int hidInputOffset = 0;
1.83 unsafe
1.84 {
1.85 byte* source = (byte*)rawInputBuffer;
1.86 - source += sizeof(RAWINPUTHEADER) + sizeof(RAWHID) + (rawInput.hid.dwSizeHid * i);
1.87 + source += sizeof(RAWINPUTHEADER) + sizeof(RAWHID) + (RawInput.hid.dwSizeHid * i);
1.88 hidInputOffset = (int)source;
1.89 }
1.90
1.91 //Copy HID input into our buffer
1.92 - Marshal.Copy(new IntPtr(hidInputOffset), InputReport, 0, (int)rawInput.hid.dwSizeHid);
1.93 + Marshal.Copy(new IntPtr(hidInputOffset), InputReport, 0, (int)RawInput.hid.dwSizeHid);
1.94
1.95 //Print HID input report in our debug output
1.96 //string hidDump = "HID input report: " + InputReportString();
1.97 @@ -196,14 +200,14 @@
1.98 }
1.99 }
1.100 }
1.101 - else if (rawInput.header.dwType == RawInputDeviceType.RIM_TYPEMOUSE)
1.102 + else if (RawInput.header.dwType == RawInputDeviceType.RIM_TYPEMOUSE)
1.103 {
1.104 IsMouse = true;
1.105
1.106 Debug.WriteLine("WM_INPUT source device is Mouse.");
1.107 // do mouse handling...
1.108 }
1.109 - else if (rawInput.header.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD)
1.110 + else if (RawInput.header.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD)
1.111 {
1.112 IsKeyboard = true;
1.113