Cleaning and adding GetRawInputDeviceInfo definition.
We will need to use it to get the Usage Page of HID messages.
1.1 --- a/RemoteControlDevice.cs Tue Nov 04 20:58:19 2014 +0100
1.2 +++ b/RemoteControlDevice.cs Tue Nov 04 22:11:01 2014 +0100
1.3 @@ -277,6 +277,9 @@
1.4 [DllImport("User32.dll")]
1.5 extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader);
1.6
1.7 + [DllImport("User32.dll")]
1.8 + extern static uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
1.9 +
1.10
1.11 private const int WM_KEYDOWN = 0x0100;
1.12 private const int WM_APPCOMMAND = 0x0319;
1.13 @@ -538,15 +541,15 @@
1.14 {
1.15 byte* source = (byte*)buffer;
1.16 source += sizeof(RAWINPUTHEADER) + sizeof(RAWHID);
1.17 - //source += 1;
1.18 pRawData = (int)source;
1.19 }
1.20 - //int pRawData = buffer.ToUint32() + Marshal.SizeOf(typeof(RAWINPUT)) + 1;
1.21
1.22 - //Marshal.Copy(new IntPtr(pRawData), bRawData, 0, raw.hid.dwSizeHid - 1);
1.23 + //Copy HID message into our buffer
1.24 Marshal.Copy(new IntPtr(pRawData), bRawData, 0, raw.hid.dwSizeHid);
1.25 - //int rawData = bRawData[0] | bRawData[1] << 8;
1.26 + //bRawData[0] //Not sure what's the meaning of the code at offset 0
1.27 + //TODO: check size before access
1.28 int rawData = bRawData[1]; //Get button code
1.29 + //Print HID codes in our debug output
1.30 Debug.WriteLine("HID " + raw.hid.dwCount + "/" + raw.hid.dwSizeHid + ":" + bRawData[0].ToString("X2") + bRawData[1].ToString("X2"));
1.31
1.32 if (Enum.IsDefined(typeof(MceButton), rawData) && rawData!=0) //Our button is a known MCE button