Adding most basic raw device list.
1.1 --- a/HidDevice.cs Sun Feb 15 13:30:54 2015 +0100
1.2 +++ b/HidDevice.cs Sun Feb 15 18:15:41 2015 +0100
1.3 @@ -10,6 +10,7 @@
1.4 {
1.5 /// <summary>
1.6 /// Represent a HID device.
1.7 + /// Rename to RawInputDevice?
1.8 /// </summary>
1.9 public class HidDevice: IDisposable
1.10 {
1.11 @@ -76,10 +77,10 @@
1.12 iInputValueCapabilities = null;
1.13
1.14 //Fetch various information defining the given HID device
1.15 - Name = Win32.Utils.RawInput.GetDeviceName(hRawInputDevice);
1.16 + Name = Win32.RawInput.GetDeviceName(hRawInputDevice);
1.17
1.18 //Get our HID descriptor pre-parsed data
1.19 - PreParsedData = Win32.Utils.RawInput.GetPreParsedData(hRawInputDevice);
1.20 + PreParsedData = Win32.RawInput.GetPreParsedData(hRawInputDevice);
1.21 if (PreParsedData == IntPtr.Zero)
1.22 {
1.23 throw new Exception("HidDevice: GetPreParsedData failed: " + Marshal.GetLastWin32Error().ToString());
1.24 @@ -87,7 +88,7 @@
1.25
1.26 //Fetch device info
1.27 iInfo = new RID_DEVICE_INFO();
1.28 - if (!Win32.Utils.RawInput.GetDeviceInfo(hRawInputDevice, ref iInfo))
1.29 + if (!Win32.RawInput.GetDeviceInfo(hRawInputDevice, ref iInfo))
1.30 {
1.31 throw new Exception("HidDevice: GetDeviceInfo failed: " + Marshal.GetLastWin32Error().ToString());
1.32 }
2.1 --- a/HidEvent.cs Sun Feb 15 13:30:54 2015 +0100
2.2 +++ b/HidEvent.cs Sun Feb 15 18:15:41 2015 +0100
2.3 @@ -106,7 +106,7 @@
2.4 {
2.5 //Fetch raw input
2.6 RAWINPUT rawInput = new RAWINPUT();
2.7 - if (!Win32.Utils.RawInput.GetRawInputData(aMessage.LParam, ref rawInput, ref rawInputBuffer))
2.8 + if (!Win32.RawInput.GetRawInputData(aMessage.LParam, ref rawInput, ref rawInputBuffer))
2.9 {
2.10 return;
2.11 }
2.12 @@ -115,7 +115,7 @@
2.13 //Get various information about this HID device
2.14 Device = new Hid.HidDevice(rawInput.header.hDevice);
2.15
2.16 - if (rawInput.header.dwType == Const.RIM_TYPEHID) //Check that our raw input is HID
2.17 + if (rawInput.header.dwType == Win32.RawInputDeviceType.RIM_TYPEHID) //Check that our raw input is HID
2.18 {
2.19 IsGeneric = true;
2.20
2.21 @@ -191,14 +191,14 @@
2.22 }
2.23 }
2.24 }
2.25 - else if (rawInput.header.dwType == Const.RIM_TYPEMOUSE)
2.26 + else if (rawInput.header.dwType == RawInputDeviceType.RIM_TYPEMOUSE)
2.27 {
2.28 IsMouse = true;
2.29
2.30 Debug.WriteLine("WM_INPUT source device is Mouse.");
2.31 // do mouse handling...
2.32 }
2.33 - else if (rawInput.header.dwType == Const.RIM_TYPEKEYBOARD)
2.34 + else if (rawInput.header.dwType == RawInputDeviceType.RIM_TYPEKEYBOARD)
2.35 {
2.36 IsKeyboard = true;
2.37
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/MainForm.Designer.cs Sun Feb 15 18:15:41 2015 +0100
3.3 @@ -0,0 +1,179 @@
3.4 +using System;
3.5 +using System.Collections.Generic;
3.6 +using System.Text;
3.7 +
3.8 +namespace RemoteControlSample
3.9 +{
3.10 + public partial class MainForm
3.11 + {
3.12 + #region Windows Form Designer generated code
3.13 + /// <summary>
3.14 + /// Required method for Designer support - do not modify
3.15 + /// the contents of this method with the code editor.
3.16 + /// </summary>
3.17 + private void InitializeComponent()
3.18 + {
3.19 + this.labelButtonName = new System.Windows.Forms.Label();
3.20 + this.labelDeviceName = new System.Windows.Forms.Label();
3.21 + this.buttonClear = new System.Windows.Forms.Button();
3.22 + this.tabControl = new System.Windows.Forms.TabControl();
3.23 + this.tabPageMessages = new System.Windows.Forms.TabPage();
3.24 + this.listViewEvents = new System.Windows.Forms.ListView();
3.25 + this.columnHeaderUsages = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
3.26 + this.columnHeaderInputReport = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
3.27 + this.columnHeaderUsagePage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
3.28 + this.columnHeaderUsageCollection = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
3.29 + this.columnHeaderRepeat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
3.30 + this.columnHeaderTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
3.31 + this.tabPageDevices = new System.Windows.Forms.TabPage();
3.32 + this.treeViewDevices = new System.Windows.Forms.TreeView();
3.33 + this.tabControl.SuspendLayout();
3.34 + this.tabPageMessages.SuspendLayout();
3.35 + this.tabPageDevices.SuspendLayout();
3.36 + this.SuspendLayout();
3.37 + //
3.38 + // labelButtonName
3.39 + //
3.40 + this.labelButtonName.AutoSize = true;
3.41 + this.labelButtonName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
3.42 + this.labelButtonName.Location = new System.Drawing.Point(788, 150);
3.43 + this.labelButtonName.Name = "labelButtonName";
3.44 + this.labelButtonName.Size = new System.Drawing.Size(103, 20);
3.45 + this.labelButtonName.TabIndex = 0;
3.46 + this.labelButtonName.Text = "Button Name";
3.47 + //
3.48 + // labelDeviceName
3.49 + //
3.50 + this.labelDeviceName.AutoSize = true;
3.51 + this.labelDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
3.52 + this.labelDeviceName.Location = new System.Drawing.Point(788, 130);
3.53 + this.labelDeviceName.Name = "labelDeviceName";
3.54 + this.labelDeviceName.Size = new System.Drawing.Size(103, 20);
3.55 + this.labelDeviceName.TabIndex = 1;
3.56 + this.labelDeviceName.Text = "Device Name";
3.57 + //
3.58 + // buttonClear
3.59 + //
3.60 + this.buttonClear.Location = new System.Drawing.Point(816, 104);
3.61 + this.buttonClear.Name = "buttonClear";
3.62 + this.buttonClear.Size = new System.Drawing.Size(75, 23);
3.63 + this.buttonClear.TabIndex = 3;
3.64 + this.buttonClear.Text = "Clear";
3.65 + this.buttonClear.UseVisualStyleBackColor = true;
3.66 + this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
3.67 + //
3.68 + // tabControl
3.69 + //
3.70 + this.tabControl.Controls.Add(this.tabPageMessages);
3.71 + this.tabControl.Controls.Add(this.tabPageDevices);
3.72 + this.tabControl.Location = new System.Drawing.Point(12, 12);
3.73 + this.tabControl.Name = "tabControl";
3.74 + this.tabControl.SelectedIndex = 0;
3.75 + this.tabControl.Size = new System.Drawing.Size(902, 514);
3.76 + this.tabControl.TabIndex = 4;
3.77 + //
3.78 + // tabPageMessages
3.79 + //
3.80 + this.tabPageMessages.Controls.Add(this.listViewEvents);
3.81 + this.tabPageMessages.Controls.Add(this.buttonClear);
3.82 + this.tabPageMessages.Controls.Add(this.labelDeviceName);
3.83 + this.tabPageMessages.Controls.Add(this.labelButtonName);
3.84 + this.tabPageMessages.Location = new System.Drawing.Point(4, 22);
3.85 + this.tabPageMessages.Name = "tabPageMessages";
3.86 + this.tabPageMessages.Padding = new System.Windows.Forms.Padding(3);
3.87 + this.tabPageMessages.Size = new System.Drawing.Size(894, 488);
3.88 + this.tabPageMessages.TabIndex = 0;
3.89 + this.tabPageMessages.Text = "Messages";
3.90 + this.tabPageMessages.UseVisualStyleBackColor = true;
3.91 + //
3.92 + // listViewEvents
3.93 + //
3.94 + this.listViewEvents.Alignment = System.Windows.Forms.ListViewAlignment.Left;
3.95 + this.listViewEvents.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
3.96 + | System.Windows.Forms.AnchorStyles.Left)));
3.97 + this.listViewEvents.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
3.98 + this.listViewEvents.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
3.99 + this.columnHeaderUsages,
3.100 + this.columnHeaderInputReport,
3.101 + this.columnHeaderUsagePage,
3.102 + this.columnHeaderUsageCollection,
3.103 + this.columnHeaderRepeat,
3.104 + this.columnHeaderTime});
3.105 + this.listViewEvents.GridLines = true;
3.106 + this.listViewEvents.Location = new System.Drawing.Point(8, 6);
3.107 + this.listViewEvents.Name = "listViewEvents";
3.108 + this.listViewEvents.Size = new System.Drawing.Size(744, 474);
3.109 + this.listViewEvents.TabIndex = 3;
3.110 + this.listViewEvents.UseCompatibleStateImageBehavior = false;
3.111 + this.listViewEvents.View = System.Windows.Forms.View.Details;
3.112 + //
3.113 + // columnHeaderUsages
3.114 + //
3.115 + this.columnHeaderUsages.Text = "Usages";
3.116 + this.columnHeaderUsages.Width = 180;
3.117 + //
3.118 + // columnHeaderInputReport
3.119 + //
3.120 + this.columnHeaderInputReport.Text = "Input Report";
3.121 + this.columnHeaderInputReport.Width = 176;
3.122 + //
3.123 + // columnHeaderUsagePage
3.124 + //
3.125 + this.columnHeaderUsagePage.Text = "Usage Page";
3.126 + this.columnHeaderUsagePage.Width = 87;
3.127 + //
3.128 + // columnHeaderUsageCollection
3.129 + //
3.130 + this.columnHeaderUsageCollection.Text = "Usage Collection";
3.131 + this.columnHeaderUsageCollection.Width = 134;
3.132 + //
3.133 + // columnHeaderRepeat
3.134 + //
3.135 + this.columnHeaderRepeat.Text = "Repeat";
3.136 + this.columnHeaderRepeat.Width = 68;
3.137 + //
3.138 + // columnHeaderTime
3.139 + //
3.140 + this.columnHeaderTime.Text = "Time";
3.141 + this.columnHeaderTime.Width = 76;
3.142 + //
3.143 + // tabPageDevices
3.144 + //
3.145 + this.tabPageDevices.Controls.Add(this.treeViewDevices);
3.146 + this.tabPageDevices.Location = new System.Drawing.Point(4, 22);
3.147 + this.tabPageDevices.Name = "tabPageDevices";
3.148 + this.tabPageDevices.Padding = new System.Windows.Forms.Padding(3);
3.149 + this.tabPageDevices.Size = new System.Drawing.Size(918, 512);
3.150 + this.tabPageDevices.TabIndex = 1;
3.151 + this.tabPageDevices.Text = "Devices";
3.152 + this.tabPageDevices.UseVisualStyleBackColor = true;
3.153 + //
3.154 + // treeViewDevices
3.155 + //
3.156 + this.treeViewDevices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
3.157 + | System.Windows.Forms.AnchorStyles.Left)));
3.158 + this.treeViewDevices.Location = new System.Drawing.Point(8, 6);
3.159 + this.treeViewDevices.Name = "treeViewDevices";
3.160 + this.treeViewDevices.Size = new System.Drawing.Size(713, 498);
3.161 + this.treeViewDevices.TabIndex = 0;
3.162 + //
3.163 + // MainForm
3.164 + //
3.165 + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
3.166 + this.BackColor = System.Drawing.SystemColors.Control;
3.167 + this.ClientSize = new System.Drawing.Size(926, 538);
3.168 + this.Controls.Add(this.tabControl);
3.169 + this.Name = "MainForm";
3.170 + this.Text = "Remote Control Sample";
3.171 + this.Load += new System.EventHandler(this.MainForm_Load);
3.172 + this.tabControl.ResumeLayout(false);
3.173 + this.tabPageMessages.ResumeLayout(false);
3.174 + this.tabPageMessages.PerformLayout();
3.175 + this.tabPageDevices.ResumeLayout(false);
3.176 + this.ResumeLayout(false);
3.177 +
3.178 + }
3.179 + #endregion Windows Form Designer generated code
3.180 +
3.181 + }
3.182 +}
4.1 --- a/MainForm.cs Sun Feb 15 13:30:54 2015 +0100
4.2 +++ b/MainForm.cs Sun Feb 15 18:15:41 2015 +0100
4.3 @@ -11,7 +11,7 @@
4.4 /// <summary>
4.5 /// Summary description for Form1.
4.6 /// </summary>
4.7 - public class MainForm : System.Windows.Forms.Form
4.8 + public partial class MainForm : System.Windows.Forms.Form
4.9 {
4.10 /// <summary>
4.11 /// Required designer variable.
4.12 @@ -20,14 +20,18 @@
4.13 private RemoteControlDevice _remote;
4.14 private Label labelButtonName;
4.15 private Label labelDeviceName;
4.16 + private Button buttonClear;
4.17 + private TabControl tabControl;
4.18 + private TabPage tabPageMessages;
4.19 private ListView listViewEvents;
4.20 private ColumnHeader columnHeaderUsages;
4.21 + private ColumnHeader columnHeaderInputReport;
4.22 private ColumnHeader columnHeaderUsagePage;
4.23 private ColumnHeader columnHeaderUsageCollection;
4.24 private ColumnHeader columnHeaderRepeat;
4.25 private ColumnHeader columnHeaderTime;
4.26 - private Button buttonClear;
4.27 - private ColumnHeader columnHeaderInputReport;
4.28 + private TabPage tabPageDevices;
4.29 + private TreeView treeViewDevices;
4.30 private Timer _timer;
4.31
4.32 public delegate void OnHidEventDelegate(object aSender, Hid.HidEvent aHidEvent);
4.33 @@ -60,123 +64,6 @@
4.34 base.Dispose( disposing );
4.35 }
4.36
4.37 - #region Windows Form Designer generated code
4.38 - /// <summary>
4.39 - /// Required method for Designer support - do not modify
4.40 - /// the contents of this method with the code editor.
4.41 - /// </summary>
4.42 - private void InitializeComponent()
4.43 - {
4.44 - this.labelButtonName = new System.Windows.Forms.Label();
4.45 - this.labelDeviceName = new System.Windows.Forms.Label();
4.46 - this.listViewEvents = new System.Windows.Forms.ListView();
4.47 - this.columnHeaderUsages = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4.48 - this.columnHeaderUsagePage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4.49 - this.columnHeaderUsageCollection = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4.50 - this.columnHeaderRepeat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4.51 - this.columnHeaderTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4.52 - this.buttonClear = new System.Windows.Forms.Button();
4.53 - this.columnHeaderInputReport = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4.54 - this.SuspendLayout();
4.55 - //
4.56 - // labelButtonName
4.57 - //
4.58 - this.labelButtonName.AutoSize = true;
4.59 - this.labelButtonName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
4.60 - this.labelButtonName.Location = new System.Drawing.Point(811, 55);
4.61 - this.labelButtonName.Name = "labelButtonName";
4.62 - this.labelButtonName.Size = new System.Drawing.Size(103, 20);
4.63 - this.labelButtonName.TabIndex = 0;
4.64 - this.labelButtonName.Text = "Button Name";
4.65 - //
4.66 - // labelDeviceName
4.67 - //
4.68 - this.labelDeviceName.AutoSize = true;
4.69 - this.labelDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
4.70 - this.labelDeviceName.Location = new System.Drawing.Point(811, 35);
4.71 - this.labelDeviceName.Name = "labelDeviceName";
4.72 - this.labelDeviceName.Size = new System.Drawing.Size(103, 20);
4.73 - this.labelDeviceName.TabIndex = 1;
4.74 - this.labelDeviceName.Text = "Device Name";
4.75 - //
4.76 - // listViewEvents
4.77 - //
4.78 - this.listViewEvents.Alignment = System.Windows.Forms.ListViewAlignment.Left;
4.79 - this.listViewEvents.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
4.80 - | System.Windows.Forms.AnchorStyles.Left)));
4.81 - this.listViewEvents.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
4.82 - this.listViewEvents.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
4.83 - this.columnHeaderUsages,
4.84 - this.columnHeaderInputReport,
4.85 - this.columnHeaderUsagePage,
4.86 - this.columnHeaderUsageCollection,
4.87 - this.columnHeaderRepeat,
4.88 - this.columnHeaderTime});
4.89 - this.listViewEvents.GridLines = true;
4.90 - this.listViewEvents.Location = new System.Drawing.Point(12, 12);
4.91 - this.listViewEvents.Name = "listViewEvents";
4.92 - this.listViewEvents.Size = new System.Drawing.Size(766, 369);
4.93 - this.listViewEvents.TabIndex = 2;
4.94 - this.listViewEvents.UseCompatibleStateImageBehavior = false;
4.95 - this.listViewEvents.View = System.Windows.Forms.View.Details;
4.96 - //
4.97 - // columnHeaderUsages
4.98 - //
4.99 - this.columnHeaderUsages.Text = "Usages";
4.100 - this.columnHeaderUsages.Width = 180;
4.101 - //
4.102 - // columnHeaderUsagePage
4.103 - //
4.104 - this.columnHeaderUsagePage.Text = "Usage Page";
4.105 - this.columnHeaderUsagePage.Width = 87;
4.106 - //
4.107 - // columnHeaderUsageCollection
4.108 - //
4.109 - this.columnHeaderUsageCollection.Text = "Usage Collection";
4.110 - this.columnHeaderUsageCollection.Width = 134;
4.111 - //
4.112 - // columnHeaderRepeat
4.113 - //
4.114 - this.columnHeaderRepeat.Text = "Repeat";
4.115 - this.columnHeaderRepeat.Width = 68;
4.116 - //
4.117 - // columnHeaderTime
4.118 - //
4.119 - this.columnHeaderTime.Text = "Time";
4.120 - this.columnHeaderTime.Width = 76;
4.121 - //
4.122 - // buttonClear
4.123 - //
4.124 - this.buttonClear.Location = new System.Drawing.Point(839, 9);
4.125 - this.buttonClear.Name = "buttonClear";
4.126 - this.buttonClear.Size = new System.Drawing.Size(75, 23);
4.127 - this.buttonClear.TabIndex = 3;
4.128 - this.buttonClear.Text = "Clear";
4.129 - this.buttonClear.UseVisualStyleBackColor = true;
4.130 - this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
4.131 - //
4.132 - // columnHeaderInputReport
4.133 - //
4.134 - this.columnHeaderInputReport.Text = "Input Report";
4.135 - this.columnHeaderInputReport.Width = 176;
4.136 - //
4.137 - // MainForm
4.138 - //
4.139 - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
4.140 - this.BackColor = System.Drawing.SystemColors.Control;
4.141 - this.ClientSize = new System.Drawing.Size(926, 393);
4.142 - this.Controls.Add(this.buttonClear);
4.143 - this.Controls.Add(this.listViewEvents);
4.144 - this.Controls.Add(this.labelDeviceName);
4.145 - this.Controls.Add(this.labelButtonName);
4.146 - this.Name = "MainForm";
4.147 - this.Text = "Remote Control Sample";
4.148 - this.Load += new System.EventHandler(this.Form1_Load);
4.149 - this.ResumeLayout(false);
4.150 - this.PerformLayout();
4.151 -
4.152 - }
4.153 - #endregion Windows Form Designer generated code
4.154
4.155 /// <summary>
4.156 /// The main entry point for the application.
4.157 @@ -184,14 +71,19 @@
4.158 [STAThread]
4.159 static void Main()
4.160 {
4.161 + Application.EnableVisualStyles();
4.162 Application.Run(new MainForm());
4.163 }
4.164
4.165 - private void Form1_Load(object sender, System.EventArgs e)
4.166 + private void MainForm_Load(object sender, System.EventArgs e)
4.167 {
4.168 _remote = new RemoteControlDevice(this.Handle);
4.169 _remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
4.170 - _remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
4.171 + _remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
4.172 +
4.173 + //
4.174 + Win32.RawInput.PopulateDeviceList(treeViewDevices);
4.175 +
4.176 }
4.177
4.178 public void HandleHidEventThreadSafe(object aSender, Hid.HidEvent aHidEvent)
5.1 --- a/RawInput.cs Sun Feb 15 13:30:54 2015 +0100
5.2 +++ b/RawInput.cs Sun Feb 15 18:15:41 2015 +0100
5.3 @@ -1,9 +1,10 @@
5.4 using System;
5.5 using System.Runtime.InteropServices;
5.6 using System.Diagnostics;
5.7 +using System.Windows.Forms;
5.8
5.9
5.10 -namespace Win32.Utils
5.11 +namespace Win32
5.12 {
5.13 /// <summary>
5.14 /// Provide some utility functions for raw input handling.
5.15 @@ -67,7 +68,7 @@
5.16 uint deviceInfoSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
5.17 deviceInfoBuffer = Marshal.AllocHGlobal((int)deviceInfoSize);
5.18
5.19 - int res = Win32.Function.GetRawInputDeviceInfo(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize);
5.20 + int res = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.RawInputDeviceInfoType.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize);
5.21 if (res <= 0)
5.22 {
5.23 Debug.WriteLine("WM_INPUT could not read device info: " + Marshal.GetLastWin32Error().ToString());
5.24 @@ -99,8 +100,8 @@
5.25 /// <returns></returns>
5.26 public static IntPtr GetPreParsedData(IntPtr hDevice)
5.27 {
5.28 - uint ppDataSize = 256;
5.29 - int result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
5.30 + uint ppDataSize = 0;
5.31 + int result = Win32.Function.GetRawInputDeviceInfo(hDevice, RawInputDeviceInfoType.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
5.32 if (result != 0)
5.33 {
5.34 Debug.WriteLine("Failed to get raw input pre-parsed data size" + result + Marshal.GetLastWin32Error());
5.35 @@ -108,7 +109,7 @@
5.36 }
5.37
5.38 IntPtr ppData = Marshal.AllocHGlobal((int)ppDataSize);
5.39 - result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
5.40 + result = Win32.Function.GetRawInputDeviceInfo(hDevice, RawInputDeviceInfoType.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
5.41 if (result <= 0)
5.42 {
5.43 Debug.WriteLine("Failed to get raw input pre-parsed data" + result + Marshal.GetLastWin32Error());
5.44 @@ -125,7 +126,7 @@
5.45 public static string GetDeviceName(IntPtr device)
5.46 {
5.47 uint deviceNameSize = 256;
5.48 - int result = Win32.Function.GetRawInputDeviceInfo(device, Win32.Const.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize);
5.49 + int result = Win32.Function.GetRawInputDeviceInfo(device, RawInputDeviceInfoType.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize);
5.50 if (result != 0)
5.51 {
5.52 return string.Empty;
5.53 @@ -134,7 +135,7 @@
5.54 IntPtr deviceName = Marshal.AllocHGlobal((int)deviceNameSize * 2); // size is the character count not byte count
5.55 try
5.56 {
5.57 - result = Win32.Function.GetRawInputDeviceInfo(device, Win32.Const.RIDI_DEVICENAME, deviceName, ref deviceNameSize);
5.58 + result = Win32.Function.GetRawInputDeviceInfo(device, RawInputDeviceInfoType.RIDI_DEVICENAME, deviceName, ref deviceNameSize);
5.59 if (result > 0)
5.60 {
5.61 return Marshal.PtrToStringAnsi(deviceName, result - 1); // -1 for NULL termination
5.62 @@ -149,5 +150,41 @@
5.63 }
5.64
5.65
5.66 + /// <summary>
5.67 + ///
5.68 + /// </summary>
5.69 + /// <param name="aTreeView"></param>
5.70 + public static void PopulateDeviceList(TreeView aTreeView)
5.71 + {
5.72 +
5.73 + //Get our list of devices
5.74 + RAWINPUTDEVICELIST[] ridList = null;
5.75 + uint deviceCount = 0;
5.76 + int res = Win32.Function.GetRawInputDeviceList(ridList, ref deviceCount,(uint)Marshal.SizeOf(typeof(RAWINPUTDEVICELIST)));
5.77 + if (res == -1)
5.78 + {
5.79 + //Just give up then
5.80 + return;
5.81 + }
5.82 +
5.83 + ridList = new RAWINPUTDEVICELIST[deviceCount];
5.84 + res = Win32.Function.GetRawInputDeviceList(ridList, ref deviceCount, (uint)Marshal.SizeOf(typeof(RAWINPUTDEVICELIST)));
5.85 + if (res != deviceCount)
5.86 + {
5.87 + //Just give up then
5.88 + return;
5.89 + }
5.90 +
5.91 + //For each our device add an node to our treeview
5.92 + foreach (RAWINPUTDEVICELIST device in ridList)
5.93 + {
5.94 + string name=GetDeviceName(device.hDevice);
5.95 + aTreeView.Nodes.Add(name, name);
5.96 + }
5.97 +
5.98 + //TreeNode node = null;
5.99 +
5.100 + }
5.101 +
5.102 }
5.103 }
5.104 \ No newline at end of file
6.1 --- a/RemoteControlSample.csproj Sun Feb 15 13:30:54 2015 +0100
6.2 +++ b/RemoteControlSample.csproj Sun Feb 15 18:15:41 2015 +0100
6.3 @@ -131,6 +131,9 @@
6.4 <Compile Include="MainForm.cs">
6.5 <SubType>Form</SubType>
6.6 </Compile>
6.7 + <Compile Include="MainForm.Designer.cs">
6.8 + <DependentUpon>MainForm.cs</DependentUpon>
6.9 + </Compile>
6.10 <Compile Include="RawInput.cs" />
6.11 <Compile Include="RemoteControlDevice.cs">
6.12 <SubType>Code</SubType>
7.1 --- a/Win32RawInput.cs Sun Feb 15 13:30:54 2015 +0100
7.2 +++ b/Win32RawInput.cs Sun Feb 15 18:15:41 2015 +0100
7.3 @@ -13,7 +13,14 @@
7.4 public extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader);
7.5
7.6 [DllImport("User32.dll", SetLastError=true)]
7.7 - public extern static int GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
7.8 + public extern static int GetRawInputDeviceInfo(IntPtr hDevice, RawInputDeviceInfoType uiCommand, IntPtr pData, ref uint pcbSize);
7.9 +
7.10 + [DllImport("user32.dll", SetLastError = true)]
7.11 + public static extern int GetRawInputDeviceList(
7.12 + [In, Out] RAWINPUTDEVICELIST[] InputdeviceList,
7.13 + [In, Out] ref uint puiNumDevices,
7.14 + [In] uint cbSize);
7.15 +
7.16 }
7.17
7.18
7.19 @@ -64,33 +71,8 @@
7.20 public const int WM_KEYDOWN = 0x0100;
7.21 public const int WM_INPUT = 0x00FF;
7.22
7.23 - /// <summary>
7.24 - /// GetRawInputDeviceInfo pData points to a string that contains the device name.
7.25 - /// </summary>
7.26 - public const uint RIDI_DEVICENAME = 0x20000007;
7.27 - /// <summary>
7.28 - /// GetRawInputDeviceInfo For this uiCommand only, the value in pcbSize is the character count (not the byte count).
7.29 - /// </summary>
7.30 - public const uint RIDI_DEVICEINFO = 0x2000000b;
7.31 - /// <summary>
7.32 - /// GetRawInputDeviceInfo pData points to an RID_DEVICE_INFO structure.
7.33 - /// </summary>
7.34 - public const uint RIDI_PREPARSEDDATA = 0x20000005;
7.35
7.36 -
7.37 - /// <summary>
7.38 - /// Data comes from a mouse.
7.39 - /// </summary>
7.40 - public const uint RIM_TYPEMOUSE = 0;
7.41 - /// <summary>
7.42 - /// Data comes from a keyboard.
7.43 - /// </summary>
7.44 - public const uint RIM_TYPEKEYBOARD = 1;
7.45 - /// <summary>
7.46 - /// Data comes from an HID that is not a keyboard or a mouse.
7.47 - /// </summary>
7.48 - public const uint RIM_TYPEHID = 2;
7.49 -
7.50 + //
7.51 public const int RID_INPUT = 0x10000003;
7.52 public const int RID_HEADER = 0x10000005;
7.53
7.54 @@ -181,12 +163,52 @@
7.55 public const int FAPPCOMMAND_OEM = 0x1000;
7.56 }
7.57
7.58 + /// <summary>
7.59 + /// Introduced this enum for consistency and easy of use.
7.60 + /// Naming of the Win32 constants were preserved.
7.61 + /// </summary>
7.62 + public enum RawInputDeviceType : uint
7.63 + {
7.64 + /// <summary>
7.65 + /// Data comes from a mouse.
7.66 + /// </summary>
7.67 + RIM_TYPEMOUSE = 0,
7.68 + /// <summary>
7.69 + /// Data comes from a keyboard.
7.70 + /// </summary>
7.71 + RIM_TYPEKEYBOARD = 1,
7.72 + /// <summary>
7.73 + /// Data comes from an HID that is not a keyboard or a mouse.
7.74 + /// </summary>
7.75 + RIM_TYPEHID = 2
7.76 + }
7.77 +
7.78 + /// <summary>
7.79 + /// Introduced this enum for consistency and easy of use.
7.80 + /// Naming of the Win32 constants were preserved.
7.81 + /// </summary>
7.82 + public enum RawInputDeviceInfoType : uint
7.83 + {
7.84 + /// <summary>
7.85 + /// GetRawInputDeviceInfo pData points to a string that contains the device name.
7.86 + /// </summary>
7.87 + RIDI_DEVICENAME = 0x20000007,
7.88 + /// <summary>
7.89 + /// GetRawInputDeviceInfo For this uiCommand only, the value in pcbSize is the character count (not the byte count).
7.90 + /// </summary>
7.91 + RIDI_DEVICEINFO = 0x2000000b,
7.92 + /// <summary>
7.93 + /// GetRawInputDeviceInfo pData points to an RID_DEVICE_INFO structure.
7.94 + /// </summary>
7.95 + RIDI_PREPARSEDDATA = 0x20000005
7.96 + }
7.97 +
7.98
7.99 [StructLayout(LayoutKind.Sequential, Pack = 1)]
7.100 public struct RAWINPUTDEVICELIST
7.101 {
7.102 public IntPtr hDevice;
7.103 - public uint dwType;
7.104 + public RawInputDeviceType dwType;
7.105 }
7.106
7.107 [StructLayout(LayoutKind.Sequential, Pack = 1)]
7.108 @@ -206,7 +228,7 @@
7.109 public struct RAWINPUTHEADER
7.110 {
7.111 [MarshalAs(UnmanagedType.U4)]
7.112 - public int dwType;
7.113 + public RawInputDeviceType dwType;
7.114 [MarshalAs(UnmanagedType.U4)]
7.115 public int dwSize;
7.116 public IntPtr hDevice;
7.117 @@ -331,7 +353,8 @@
7.118 [FieldOffset(0)]
7.119 public uint cbSize;
7.120 [FieldOffset(4)]
7.121 - public uint dwType;
7.122 + [MarshalAsAttribute(UnmanagedType.U4)]
7.123 + public RawInputDeviceType dwType;
7.124 [FieldOffset(8)]
7.125 public RID_DEVICE_INFO_MOUSE mouse;
7.126 [FieldOffset(8)]