diff --git a/C#/AutoHotInterception/Helpers/ScanCodeHelper.cs b/C#/AutoHotInterception/Helpers/ScanCodeHelper.cs index 29cb5f0..6ffd794 100644 --- a/C#/AutoHotInterception/Helpers/ScanCodeHelper.cs +++ b/C#/AutoHotInterception/Helpers/ScanCodeHelper.cs @@ -70,6 +70,11 @@ namespace AutoHotInterception.Helpers } } + public static bool IsDoubleScanCode(List strokes) + { + return _twoStrokeKeyConverter.ContainsKey(new Tuple(strokes[0].key.code, strokes[0].key.state, strokes[1].key.code, strokes[1].key.state)); + } + /// /// Used by ProcessStrokes() KeyboardHandler to translate incoming key(s) from Interception to AHK format /// diff --git a/C#/AutoHotInterception/Manager.cs b/C#/AutoHotInterception/Manager.cs index d8f62a3..91b8d5c 100644 --- a/C#/AutoHotInterception/Manager.cs +++ b/C#/AutoHotInterception/Manager.cs @@ -560,18 +560,33 @@ namespace AutoHotInterception { // If this is a keyboard stroke, then perform another Receive immediately with a timeout of 0... // ... this is to check whether an extended stroke is waiting - if (ManagedWrapper.Receive(DeviceContext, stroke2DeviceId = ManagedWrapper.WaitWithTimeout(DeviceContext, 0), ref stroke2, 1) > 0) + // Start by building a list of all pending strokes + while (ManagedWrapper.Receive(DeviceContext, stroke2DeviceId = ManagedWrapper.WaitWithTimeout(DeviceContext, 0), ref stroke2, 1) > 0) { - if (stroke2DeviceId != stroke1DeviceId) + if (stroke2DeviceId != stroke1DeviceId) { throw new Exception("Stroke 2 DeviceId is not the same as Stroke 1 DeviceId"); } + strokes.Add(stroke2); + } + + // Loop through the list checking the first 2 indexes for valid "two-code" key combinations. + // If no combo is found, send index 0 on its way, remove it off the top of the list, repeat + while (strokes.Count > 0) + { + if (strokes.Count >= 2 && ScanCodeHelper.IsDoubleScanCode(new List { strokes[0], strokes[1] })) { - // Never seems to happen, but conceivably possible - throw new Exception("Stroke 2 DeviceId is not the same as Stroke 1 DeviceId"); + DeviceHandlers[stroke1DeviceId].ProcessStroke(new List { strokes[0], strokes[1] }); + strokes.RemoveRange(0, 2); + } + else + { + DeviceHandlers[stroke1DeviceId].ProcessStroke(new List { strokes[0] }); + strokes.RemoveAt(0); } - //Debug.WriteLine($"Second stroke: {RenderStroke(stroke2)}"); - strokes.Add(stroke2); } } - DeviceHandlers[stroke1DeviceId].ProcessStroke(strokes); + else + { + DeviceHandlers[stroke1DeviceId].ProcessStroke(strokes); + } } } _pollThreadRunning = false;