diff --git a/HandheldCompanion/Managers/InputsManager.cs b/HandheldCompanion/Managers/InputsManager.cs index c865549a4..0856df7b1 100644 --- a/HandheldCompanion/Managers/InputsManager.cs +++ b/HandheldCompanion/Managers/InputsManager.cs @@ -42,6 +42,7 @@ public class InputsManager private bool TriggerLock; private string TriggerListener = string.Empty; private List TriggerBuffer = new(); + private List Intercepted = new(); private Dictionary Triggered = new Dictionary(); @@ -119,6 +120,11 @@ private void M_GlobalHook_KeyEvent(object? sender, KeyEventArgs e) if (Enumerable.SequenceEqual(chord_keys, buffer_keys)) { + Intercepted.Clear(); + Intercepted.AddRange(TriggerBuffer); + + TriggerBuffer.Clear(); + long time_last = TIME_BURST; long time_duration = time_last; @@ -132,44 +138,42 @@ private void M_GlobalHook_KeyEvent(object? sender, KeyEventArgs e) time_last = args.Timestamp - prevKeyUp[listener]; prevKeyUp[listener] = args.Timestamp; } - + // skip call if too close if (time_last < TIME_BURST) break; - - // only send trigger on release - if (!args.IsKeyUp) - break; time_duration = args.Timestamp - prevKeyDown[listener]; if (time_duration > TIME_LONG) listener += " (HOLD)"; - LogManager.LogDebug("Success: {0} at {1}", listener, args.Timestamp); - + LogManager.LogDebug("Triggered: {0} at {1}", listener, args.Timestamp); + if (string.IsNullOrEmpty(TriggerListener)) { string trigger = GetTriggerFromName(listener); + // trigger isn't used if (string.IsNullOrEmpty(trigger)) + { + TriggerBuffer.AddRange(Intercepted); break; - - TriggerBuffer.Clear(); - TriggerRaised?.Invoke(trigger, Triggers[trigger]); - - return; + }else if (args.IsKeyUp) + TriggerRaised?.Invoke(trigger, Triggers[trigger]); } else { TriggerInputs inputs = new TriggerInputs(TriggerInputsType.Keyboard, string.Join(",", chord.Keys), listener); Triggers[TriggerListener] = inputs; - TriggerBuffer.Clear(); - TriggerUpdated?.Invoke(TriggerListener, inputs); - TriggerListener = string.Empty; - - return; + if (args.IsKeyUp) + { + TriggerUpdated?.Invoke(TriggerListener, inputs); + TriggerListener = string.Empty; + } } + + return; } } @@ -178,7 +182,7 @@ private void M_GlobalHook_KeyEvent(object? sender, KeyEventArgs e) private string GetTriggerFromName(string name) { - foreach(var pair in Triggers) + foreach (var pair in Triggers) { string p_trigger = pair.Key; string p_name = pair.Value.name; @@ -241,7 +245,7 @@ private void ReleaseBuffer() // clear buffer TriggerBuffer.Clear(); } - catch(Exception) + catch (Exception) { } } @@ -250,13 +254,14 @@ private List GetBufferKeys() { List keys = new List(); - foreach(KeyEventArgsExt e in TriggerBuffer) + foreach (KeyEventArgsExt e in TriggerBuffer) keys.Add((KeyCode)e.KeyValue); return keys; } - public void Start() { + public void Start() + { foreach (var pair in Triggers) Triggered[pair.Key] = false; @@ -268,7 +273,7 @@ public void Start() { prevKeyUp[listener] = TIME_BURST; prevKeyDown[listener] = TIME_BURST; } - + UpdateTimer.Start(); m_GlobalHook.KeyDown += M_GlobalHook_KeyEvent; @@ -346,7 +351,9 @@ public void StartListening(string listener) TriggerListener = listener; TriggerBuffer = new(); + // reset trigger Triggers[TriggerListener].buttons = 0; + Triggers[TriggerListener].name = ""; } public void UpdateController(ControllerEx controllerEx) @@ -354,4 +361,4 @@ public void UpdateController(ControllerEx controllerEx) this.controllerEx = controllerEx; } } -} +} \ No newline at end of file