Merge pull request #84 from bluechipps/wait-with-timeout-zero

Support for receiving more than 2 strokes at a time. Also fixes exception caused by pressing multiple keys simultaneously.
wait-with-timeout-zero
Clive Galway 2 years ago committed by GitHub
commit 8222f9b11e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,6 +70,11 @@ namespace AutoHotInterception.Helpers
}
}
public static bool IsDoubleScanCode(List<Stroke> strokes)
{
return _twoStrokeKeyConverter.ContainsKey(new Tuple<ushort, ushort, ushort, ushort>(strokes[0].key.code, strokes[0].key.state, strokes[1].key.code, strokes[1].key.state));
}
/// <summary>
/// Used by ProcessStrokes() KeyboardHandler to translate incoming key(s) from Interception to AHK format
/// </summary>

@ -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<ManagedWrapper.Stroke> { 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<ManagedWrapper.Stroke> { strokes[0], strokes[1] });
strokes.RemoveRange(0, 2);
}
else
{
DeviceHandlers[stroke1DeviceId].ProcessStroke(new List<ManagedWrapper.Stroke> { 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;

Loading…
Cancel
Save