# HG changeset patch
# User StephaneLenclud
# Date 1425498744 -3600
# Node ID e0a7b35f90dd2c461eb714802b8a859d82931171
# Parent b27d6b8527e2058e1daa84f4ba586397f4a4966c
Consolidating for keyboard and mouse device support.
Adding tests tab.
diff -r b27d6b8527e2 -r e0a7b35f90dd HidEvent.cs
--- a/HidEvent.cs Tue Mar 03 21:07:44 2015 +0100
+++ b/HidEvent.cs Wed Mar 04 20:52:24 2015 +0100
@@ -108,12 +108,17 @@
RAWINPUT rawInput = new RAWINPUT();
if (!Win32.RawInput.GetRawInputData(aMessage.LParam, ref rawInput, ref rawInputBuffer))
{
+ Debug.WriteLine("GetRawInputData failed!");
return;
}
-
- //Get various information about this HID device
- Device = new Hid.HidDevice(rawInput.header.hDevice);
+ //Our device can actually be null.
+ //This is notably happening for some keyboard events
+ if (rawInput.header.hDevice != IntPtr.Zero)
+ {
+ //Get various information about this HID device
+ Device = new Hid.HidDevice(rawInput.header.hDevice);
+ }
if (rawInput.header.dwType == Win32.RawInputDeviceType.RIM_TYPEHID) //Check that our raw input is HID
{
@@ -204,12 +209,15 @@
Debug.WriteLine("WM_INPUT source device is Keyboard.");
// do keyboard handling...
- Debug.WriteLine("Type: " + Device.Info.keyboard.dwType.ToString());
- Debug.WriteLine("SubType: " + Device.Info.keyboard.dwSubType.ToString());
- Debug.WriteLine("Mode: " + Device.Info.keyboard.dwKeyboardMode.ToString());
- Debug.WriteLine("Number of function keys: " + Device.Info.keyboard.dwNumberOfFunctionKeys.ToString());
- Debug.WriteLine("Number of indicators: " + Device.Info.keyboard.dwNumberOfIndicators.ToString());
- Debug.WriteLine("Number of keys total: " + Device.Info.keyboard.dwNumberOfKeysTotal.ToString());
+ if (Device != null)
+ {
+ Debug.WriteLine("Type: " + Device.Info.keyboard.dwType.ToString());
+ Debug.WriteLine("SubType: " + Device.Info.keyboard.dwSubType.ToString());
+ Debug.WriteLine("Mode: " + Device.Info.keyboard.dwKeyboardMode.ToString());
+ Debug.WriteLine("Number of function keys: " + Device.Info.keyboard.dwNumberOfFunctionKeys.ToString());
+ Debug.WriteLine("Number of indicators: " + Device.Info.keyboard.dwNumberOfIndicators.ToString());
+ Debug.WriteLine("Number of keys total: " + Device.Info.keyboard.dwNumberOfKeysTotal.ToString());
+ }
}
}
finally
@@ -272,7 +280,12 @@
Debug.WriteLine("==== Invalid HidEvent");
return;
}
- Device.DebugWrite();
+
+ if (Device!=null)
+ {
+ Device.DebugWrite();
+ }
+
if (IsGeneric) Debug.WriteLine("==== Generic");
if (IsKeyboard) Debug.WriteLine("==== Keyboard");
if (IsMouse) Debug.WriteLine("==== Mouse");
@@ -292,6 +305,11 @@
///
public string InputReportString()
{
+ if (InputReport == null)
+ {
+ return "null";
+ }
+
string hidDump = "";
foreach (byte b in InputReport)
{
diff -r b27d6b8527e2 -r e0a7b35f90dd MainForm.Designer.cs
--- a/MainForm.Designer.cs Tue Mar 03 21:07:44 2015 +0100
+++ b/MainForm.Designer.cs Wed Mar 04 20:52:24 2015 +0100
@@ -26,15 +26,18 @@
this.columnHeaderRepeat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tabPageDevices = new System.Windows.Forms.TabPage();
+ this.buttonTreeViewExpandAll = new System.Windows.Forms.Button();
+ this.buttonTreeViewCollapseAll = new System.Windows.Forms.Button();
this.treeViewDevices = new System.Windows.Forms.TreeView();
- this.buttonTreeViewCollapseAll = new System.Windows.Forms.Button();
- this.buttonTreeViewExpandAll = new System.Windows.Forms.Button();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelDevice = new System.Windows.Forms.ToolStripStatusLabel();
+ this.tabPageTests = new System.Windows.Forms.TabPage();
+ this.textBoxTests = new System.Windows.Forms.TextBox();
this.tabControl.SuspendLayout();
this.tabPageMessages.SuspendLayout();
this.tabPageDevices.SuspendLayout();
this.statusStrip.SuspendLayout();
+ this.tabPageTests.SuspendLayout();
this.SuspendLayout();
//
// labelButtonName
@@ -73,6 +76,7 @@
| System.Windows.Forms.AnchorStyles.Left)));
this.tabControl.Controls.Add(this.tabPageMessages);
this.tabControl.Controls.Add(this.tabPageDevices);
+ this.tabControl.Controls.Add(this.tabPageTests);
this.tabControl.Location = new System.Drawing.Point(12, 12);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
@@ -88,7 +92,7 @@
this.tabPageMessages.Location = new System.Drawing.Point(4, 22);
this.tabPageMessages.Name = "tabPageMessages";
this.tabPageMessages.Padding = new System.Windows.Forms.Padding(3);
- this.tabPageMessages.Size = new System.Drawing.Size(894, 488);
+ this.tabPageMessages.Size = new System.Drawing.Size(894, 506);
this.tabPageMessages.TabIndex = 0;
this.tabPageMessages.Text = "Messages";
this.tabPageMessages.UseVisualStyleBackColor = true;
@@ -109,7 +113,7 @@
this.listViewEvents.GridLines = true;
this.listViewEvents.Location = new System.Drawing.Point(8, 6);
this.listViewEvents.Name = "listViewEvents";
- this.listViewEvents.Size = new System.Drawing.Size(744, 474);
+ this.listViewEvents.Size = new System.Drawing.Size(744, 492);
this.listViewEvents.TabIndex = 3;
this.listViewEvents.UseCompatibleStateImageBehavior = false;
this.listViewEvents.View = System.Windows.Forms.View.Details;
@@ -157,14 +161,15 @@
this.tabPageDevices.Text = "Devices";
this.tabPageDevices.UseVisualStyleBackColor = true;
//
- // treeViewDevices
+ // buttonTreeViewExpandAll
//
- this.treeViewDevices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.treeViewDevices.Location = new System.Drawing.Point(8, 6);
- this.treeViewDevices.Name = "treeViewDevices";
- this.treeViewDevices.Size = new System.Drawing.Size(713, 492);
- this.treeViewDevices.TabIndex = 0;
+ this.buttonTreeViewExpandAll.Location = new System.Drawing.Point(813, 6);
+ this.buttonTreeViewExpandAll.Name = "buttonTreeViewExpandAll";
+ this.buttonTreeViewExpandAll.Size = new System.Drawing.Size(75, 23);
+ this.buttonTreeViewExpandAll.TabIndex = 2;
+ this.buttonTreeViewExpandAll.Text = "Expand All";
+ this.buttonTreeViewExpandAll.UseVisualStyleBackColor = true;
+ this.buttonTreeViewExpandAll.Click += new System.EventHandler(this.buttonTreeViewExpandAll_Click);
//
// buttonTreeViewCollapseAll
//
@@ -176,15 +181,14 @@
this.buttonTreeViewCollapseAll.UseVisualStyleBackColor = true;
this.buttonTreeViewCollapseAll.Click += new System.EventHandler(this.buttonTreeViewCollapseAll_Click);
//
- // buttonTreeViewExpandAll
+ // treeViewDevices
//
- this.buttonTreeViewExpandAll.Location = new System.Drawing.Point(813, 6);
- this.buttonTreeViewExpandAll.Name = "buttonTreeViewExpandAll";
- this.buttonTreeViewExpandAll.Size = new System.Drawing.Size(75, 23);
- this.buttonTreeViewExpandAll.TabIndex = 2;
- this.buttonTreeViewExpandAll.Text = "Expand All";
- this.buttonTreeViewExpandAll.UseVisualStyleBackColor = true;
- this.buttonTreeViewExpandAll.Click += new System.EventHandler(this.buttonTreeViewExpandAll_Click);
+ this.treeViewDevices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)));
+ this.treeViewDevices.Location = new System.Drawing.Point(8, 6);
+ this.treeViewDevices.Name = "treeViewDevices";
+ this.treeViewDevices.Size = new System.Drawing.Size(713, 492);
+ this.treeViewDevices.TabIndex = 0;
//
// statusStrip
//
@@ -202,6 +206,24 @@
this.toolStripStatusLabelDevice.Size = new System.Drawing.Size(61, 17);
this.toolStripStatusLabelDevice.Text = "No Device";
//
+ // tabPageTests
+ //
+ this.tabPageTests.Controls.Add(this.textBoxTests);
+ this.tabPageTests.Location = new System.Drawing.Point(4, 22);
+ this.tabPageTests.Name = "tabPageTests";
+ this.tabPageTests.Size = new System.Drawing.Size(894, 506);
+ this.tabPageTests.TabIndex = 2;
+ this.tabPageTests.Text = "Tests";
+ this.tabPageTests.UseVisualStyleBackColor = true;
+ //
+ // textBoxTests
+ //
+ this.textBoxTests.Location = new System.Drawing.Point(4, 4);
+ this.textBoxTests.Multiline = true;
+ this.textBoxTests.Name = "textBoxTests";
+ this.textBoxTests.Size = new System.Drawing.Size(887, 499);
+ this.textBoxTests.TabIndex = 0;
+ //
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
@@ -218,6 +240,8 @@
this.tabPageDevices.ResumeLayout(false);
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
+ this.tabPageTests.ResumeLayout(false);
+ this.tabPageTests.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -228,6 +252,8 @@
private System.Windows.Forms.Button buttonTreeViewCollapseAll;
private System.Windows.Forms.StatusStrip statusStrip;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelDevice;
+ private System.Windows.Forms.TabPage tabPageTests;
+ private System.Windows.Forms.TextBox textBoxTests;
}
}
diff -r b27d6b8527e2 -r e0a7b35f90dd RawInput.cs
--- a/RawInput.cs Tue Mar 03 21:07:44 2015 +0100
+++ b/RawInput.cs Wed Mar 04 20:52:24 2015 +0100
@@ -151,7 +151,7 @@
///
- ///
+ /// Populate the given tree-view control with our Raw Input Devices.
///
///
public static void PopulateDeviceList(TreeView aTreeView)
diff -r b27d6b8527e2 -r e0a7b35f90dd RemoteControlDevice.cs
--- a/RemoteControlDevice.cs Tue Mar 03 21:07:44 2015 +0100
+++ b/RemoteControlDevice.cs Wed Mar 04 20:52:24 2015 +0100
@@ -179,7 +179,7 @@
// remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
// for the vendor defined usage page.
- RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[4];
+ RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[6];
int i = 0;
rid[i].usUsagePage = (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl;
@@ -205,21 +205,21 @@
rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
rid[i].hwndTarget = aHWND;
- //i++;
+ i++;
rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.GamePad;
rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
rid[i].hwndTarget = aHWND;
- //i++;
- //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
- //rid[i].usUsage = (ushort)Hid.UsageCollectionGenericDesktop.Keyboard;
+ i++;
+ rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
+ rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Keyboard;
//rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
- //rid[i].hwndTarget = aHWND;
+ rid[i].hwndTarget = aHWND;
//i++;
//rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
- //rid[i].usUsage = (ushort)Hid.UsageCollectionGenericDesktop.Mouse;
+ //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse;
//rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
//rid[i].hwndTarget = aHWND;