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