# HG changeset patch # User StephaneLenclud # Date 1426602958 -3600 # Node ID 2d5955694057865e75856f638bd406c4537c6572 # Parent 312160defeac87de35bf6150b560db20c45d0389 Switch solution to 2013. Event repeat now a Handler option. Handler now deregisters devices when disposed. Adding Thinkpad custom usages. diff -r 312160defeac -r 2d5955694057 Hid/HidEvent.cs --- a/Hid/HidEvent.cs Sun Mar 15 21:26:51 2015 +0100 +++ b/Hid/HidEvent.cs Tue Mar 17 15:35:58 2015 +0100 @@ -115,7 +115,7 @@ /// Initialize an HidEvent from a WM_INPUT message /// /// Device Handle as provided by RAWINPUTHEADER.hDevice, typically accessed as rawinput.header.hDevice - public Event(Message aMessage, HidEventRepeatDelegate aRepeatDelegate) + public Event(Message aMessage, HidEventRepeatDelegate aRepeatDelegate, bool aRepeat) { RepeatCount = 0; IsValid = false; @@ -236,10 +236,10 @@ } // - if (IsButtonDown) + if (IsButtonDown && aRepeat) { //TODO: Make this optional - //StartRepeatTimer(iRepeatDelay); + StartRepeatTimer(iRepeatDelay); } IsValid = true; @@ -527,20 +527,12 @@ } UsagePage usagePage = (UsagePage)UsagePage; - switch (usagePage) + string name = Enum.GetName(Utils.UsageType(usagePage), usage); + if (name == null) { - case Hid.UsagePage.Consumer: - usageText += ((ConsumerControl)usage).ToString(); - break; - - case Hid.UsagePage.WindowsMediaCenterRemoteControl: - usageText += ((WindowsMediaCenterRemoteControl)usage).ToString(); - break; - - default: - usageText += usage.ToString("X2"); - break; + name += usage.ToString("X2"); } + usageText += name; } //If we are a gamepad display axis and dpad values diff -r 312160defeac -r 2d5955694057 Hid/HidHandler.cs --- a/Hid/HidHandler.cs Sun Mar 15 21:26:51 2015 +0100 +++ b/Hid/HidHandler.cs Tue Mar 17 15:35:58 2015 +0100 @@ -33,19 +33,40 @@ /// /// Our HID handler manages raw input registrations, processes WM_INPUT messages and broadcasts HID events in return. /// - public class Handler + public class Handler : IDisposable { public delegate void HidEventHandler(object aSender, Event aHidEvent); public event HidEventHandler OnHidEvent; List iHidEvents; + RAWINPUTDEVICE[] iRawInputDevices; public bool IsRegistered { get; private set; } + public bool ManageRepeats { get; private set; } - public Handler(RAWINPUTDEVICE[] aRawInputDevices) + public Handler(RAWINPUTDEVICE[] aRawInputDevices, bool aManageRepeats=false) { - iHidEvents=new List(); - IsRegistered = Function.RegisterRawInputDevices(aRawInputDevices, (uint)aRawInputDevices.Length, (uint)Marshal.SizeOf(aRawInputDevices[0])); + iRawInputDevices = aRawInputDevices; + iHidEvents = new List(); + IsRegistered = Function.RegisterRawInputDevices(iRawInputDevices, (uint)iRawInputDevices.Length, (uint)Marshal.SizeOf(iRawInputDevices[0])); + ManageRepeats = aManageRepeats; + } + + /// + /// Will de-register devices. + /// + public void Dispose() + { + //Setup device removal + for (int i=0; i @@ -60,7 +81,7 @@ return; } - Event hidEvent = new Event(aMessage, OnHidEventRepeat); + Event hidEvent = new Event(aMessage, OnHidEventRepeat, ManageRepeats); hidEvent.DebugWrite(); if (!hidEvent.IsValid || !hidEvent.IsGeneric) @@ -70,23 +91,26 @@ } // - if (hidEvent.IsButtonUp) + if (ManageRepeats) { - //This is a key up event - //We need to discard any events belonging to the same page and collection - for (int i = (iHidEvents.Count-1); i >= 0; i--) + if (hidEvent.IsButtonUp) { - if (iHidEvents[i].UsageId == hidEvent.UsageId) + //This is a key up event + //We need to discard any events belonging to the same page and collection + for (int i = (iHidEvents.Count - 1); i >= 0; i--) { - iHidEvents[i].Dispose(); - iHidEvents.RemoveAt(i); + if (iHidEvents[i].UsageId == hidEvent.UsageId) + { + iHidEvents[i].Dispose(); + iHidEvents.RemoveAt(i); + } } } - } - else - { - //Keep that event until we get a key up message - iHidEvents.Add(hidEvent); + else + { + //Keep that event until we get a key up message + iHidEvents.Add(hidEvent); + } } //Broadcast our events diff -r 312160defeac -r 2d5955694057 Hid/HidUsageTables.cs --- a/Hid/HidUsageTables.cs Sun Mar 15 21:26:51 2015 +0100 +++ b/Hid/HidUsageTables.cs Tue Mar 17 15:35:58 2015 +0100 @@ -22,7 +22,7 @@ /// /// From USB HID usage tables. /// http://www.usb.org/developers/hidpage#HID_Usage - /// http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf + /// http://www.usb.org/developers/hidpage/Hut1_12v2.pdf /// public enum UsagePage : ushort { @@ -322,6 +322,19 @@ Microphone = 0x04, Headphone = 0x05, GraphicEqualizer = 0x06, + ThinkPadMicrophoneMute = 0x10, //Custom + ThinkPadVantage = 0x11, //Custom + ThinkPadSystemLock = 0x12, //Custom + ThinkPadPowerManagement = 0x13, //Custom + ThinkPadWirelessNetwork = 0x14, //Custom + ThinkPadCamera = 0x15, //Custom + ThinkPadDisplayScheme = 0x16, //Custom + ThinkPadMouseProperties = 0x17, //Custom + ThinkPadEject = 0x18, //Custom + ThinkPadSystemHibernate = 0x19, //Custom + ThinkPadBrightnessIncrement = 0x1A, //Custom + ThinkPadBrightnessDecrement = 0x1B, //Custom + ThinkPadFullscreenMagnifier = 0x1D, //Custom Plus10 = 0x20, Plus100 = 0x21, AmPm = 0x22, diff -r 312160defeac -r 2d5955694057 MainForm.Designer.cs --- a/MainForm.Designer.cs Sun Mar 15 21:26:51 2015 +0100 +++ b/MainForm.Designer.cs Tue Mar 17 15:35:58 2015 +0100 @@ -51,6 +51,7 @@ this.textBoxTests = new System.Windows.Forms.TextBox(); this.statusStrip = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabelDevice = new System.Windows.Forms.ToolStripStatusLabel(); + this.checkBoxRepeat = new System.Windows.Forms.CheckBox(); this.tabControl.SuspendLayout(); this.tabPageMessages.SuspendLayout(); this.tabPageDevices.SuspendLayout(); @@ -83,6 +84,7 @@ // // tabPageMessages // + this.tabPageMessages.Controls.Add(this.checkBoxRepeat); this.tabPageMessages.Controls.Add(this.listViewEvents); this.tabPageMessages.Controls.Add(this.buttonClear); this.tabPageMessages.Location = new System.Drawing.Point(4, 22); @@ -231,6 +233,17 @@ this.toolStripStatusLabelDevice.Size = new System.Drawing.Size(61, 17); this.toolStripStatusLabelDevice.Text = "No Device"; // + // checkBoxRepeat + // + this.checkBoxRepeat.AutoSize = true; + this.checkBoxRepeat.Location = new System.Drawing.Point(813, 46); + this.checkBoxRepeat.Name = "checkBoxRepeat"; + this.checkBoxRepeat.Size = new System.Drawing.Size(61, 17); + this.checkBoxRepeat.TabIndex = 4; + this.checkBoxRepeat.Text = "Repeat"; + this.checkBoxRepeat.UseVisualStyleBackColor = true; + this.checkBoxRepeat.CheckedChanged += new System.EventHandler(this.checkBoxRepeat_CheckedChanged); + // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); @@ -243,6 +256,7 @@ this.Load += new System.EventHandler(this.MainForm_Load); this.tabControl.ResumeLayout(false); this.tabPageMessages.ResumeLayout(false); + this.tabPageMessages.PerformLayout(); this.tabPageDevices.ResumeLayout(false); this.tabPageTests.ResumeLayout(false); this.tabPageTests.PerformLayout(); @@ -273,6 +287,7 @@ private System.Windows.Forms.TabPage tabPageTests; private System.Windows.Forms.TextBox textBoxTests; private System.Windows.Forms.Button buttonRefresh; + private System.Windows.Forms.CheckBox checkBoxRepeat; } } diff -r 312160defeac -r 2d5955694057 MainForm.cs --- a/MainForm.cs Sun Mar 15 21:26:51 2015 +0100 +++ b/MainForm.cs Tue Mar 17 15:35:58 2015 +0100 @@ -69,6 +69,14 @@ // 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. + if (iHidHandler!=null) + { + //First de-register + iHidHandler.Dispose(); + iHidHandler = null; + } + + RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5]; int i = 0; @@ -114,7 +122,7 @@ //rid[i].hwndTarget = aHWND; - iHidHandler = new SharpLib.Hid.Handler(rid); + iHidHandler = new SharpLib.Hid.Handler(rid, checkBoxRepeat.Checked); if (!iHidHandler.IsRegistered) { Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString()); @@ -182,5 +190,10 @@ SharpLib.Win32.RawInput.PopulateDeviceList(treeViewDevices); } + private void checkBoxRepeat_CheckedChanged(object sender, EventArgs e) + { + RegisterHidDevices(); + } + } } diff -r 312160defeac -r 2d5955694057 Rebracer.xml --- a/Rebracer.xml Sun Mar 15 21:26:51 2015 +0100 +++ b/Rebracer.xml Tue Mar 17 15:35:58 2015 +0100 @@ -11,8 +11,8 @@ TODO:2 - HACK:2 - UNDONE:2 + UNDONE:2 + HACK:2 UnresolvedMergeConflict:3 true @@ -93,7 +93,7 @@ true true true - Implicit (Windows)|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\libhelp.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\sitetypesWindows.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\domWindows.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\underscorefilter.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\showPlainComments.js;Implicit (Web)|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\libhelp.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\sitetypesWeb.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\domWeb.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\underscorefilter.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\showPlainComments.js|~/Scripts/_references.js;Dedicated Worker|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\libhelp.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\dedicatedworker.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\underscorefilter.js|C:\Program Files (x86)\Microsoft Visual Studio 11.0\JavaScript\References\showPlainComments.js; + Implicit (Windows 8)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindows_8.0.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindows_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows Phone 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindowsPhone_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Web)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWeb.js|$(VSInstallDir)\JavaScript\References\domWeb.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js|~/Scripts/_references.js;Dedicated Worker|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\dedicatedworker.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Generic|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js; true true true diff -r 312160defeac -r 2d5955694057 SharpLibHid.sln --- a/SharpLibHid.sln Sun Mar 15 21:26:51 2015 +0100 +++ b/SharpLibHid.sln Tue Mar 17 15:35:58 2015 +0100 @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E70B5E73-7045-4EA7-968D-06BB68773DAB}" ProjectSection(SolutionItems) = preProject Rebracer.xml = Rebracer.xml diff -r 312160defeac -r 2d5955694057 Win32/Win32RawInput.cs --- a/Win32/Win32RawInput.cs Sun Mar 15 21:26:51 2015 +0100 +++ b/Win32/Win32RawInput.cs Tue Mar 17 15:35:58 2015 +0100 @@ -110,7 +110,7 @@ /// /// If set, the application command keys are handled. RIDEV_APPKEYS can be specified only if RIDEV_NOLEGACY is specified for a keyboard device. - /// + /// public const uint RIDEV_APPKEYS = 0x00000400; ///