From 6d96cbfb5bb171bb9da48edcd9653dfb31af1a97 Mon Sep 17 00:00:00 2001 From: Clive Galway Date: Sat, 15 Jan 2022 17:46:03 +0000 Subject: [PATCH] Add SetContextCallback --- .../DeviceHandlers/KeyboardHandler.cs | 16 ++++++++++++---- C#/AutoHotInterception/Manager.cs | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/C#/AutoHotInterception/DeviceHandlers/KeyboardHandler.cs b/C#/AutoHotInterception/DeviceHandlers/KeyboardHandler.cs index 628566d..1b21808 100644 --- a/C#/AutoHotInterception/DeviceHandlers/KeyboardHandler.cs +++ b/C#/AutoHotInterception/DeviceHandlers/KeyboardHandler.cs @@ -81,12 +81,20 @@ namespace AutoHotInterception.DeviceHandlers } } + /// + /// Enables Context Mode for this keyboard + /// + /// The callback to call when input happens + public void SetContextCallback(dynamic callback) + { + ContextCallback = callback; + } + public override void ProcessStroke(ManagedWrapper.Stroke stroke) { //ManagedWrapper.Send(DeviceContext, _deviceId, ref stroke, 1); var hasSubscription = false; - //var hasContext = ContextCallbacks.ContainsKey(i); - var hasContext = false; + var hasContext = ContextCallback != null; // Process any waiting input for this keyboard var block = false; @@ -157,13 +165,13 @@ namespace AutoHotInterception.DeviceHandlers // If this key had no subscriptions, but Context Mode is set for this keyboard... // ... then set the Context before sending the key - //if (!hasSubscription && hasContext) ContextCallbacks[i](1); + if (!hasSubscription && hasContext) ContextCallback(1); // Pass the key through to the OS. ManagedWrapper.Send(DeviceContext, _deviceId, ref stroke, 1); // If we are processing Context Mode, then Unset the context variable after sending the key - //if (!hasSubscription && hasContext) ContextCallbacks[i](0); + if (!hasSubscription && hasContext) ContextCallback(0); } } } diff --git a/C#/AutoHotInterception/Manager.cs b/C#/AutoHotInterception/Manager.cs index b0a7513..6c0804c 100644 --- a/C#/AutoHotInterception/Manager.cs +++ b/C#/AutoHotInterception/Manager.cs @@ -372,7 +372,15 @@ namespace AutoHotInterception if (id < 1 || id > 20) throw new ArgumentOutOfRangeException(nameof(id), "DeviceIds must be between 1 and 20"); - ContextCallbacks[id] = callback; + if (id < 11) + { + var device = (KeyboardHandler)DeviceHandlers[id]; + device.SetContextCallback(callback); + } + else + { + + } SetDeviceFilterState(id, true); SetFilterState(true);