Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update KeyboardHandler.cs
  • Loading branch information
bluechipps authored Mar 30, 2023
commit 37dd5b9855287fde89d52d74621aecdad6239f2c
28 changes: 26 additions & 2 deletions C#/AutoHotInterception/DeviceHandlers/KeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override void DisableFilterIfNeeded()
{
if (AllButtonsMapping == null
&& SingleButtonMappings.Count == 0
&& SingleButtonMappingsEx.Count == 0
&& ContextCallback == null)
{
_isFiltered = false;
Expand Down Expand Up @@ -56,6 +57,7 @@ public override void ProcessStroke(List<ManagedWrapper.Stroke> strokes)
if (_isFiltered)
{
var isKeyMapping = false; // True if this is a mapping to a single key, else it would be a mapping to a whole device
var useExtendedCallback = false;
var processedState = ScanCodeHelper.TranslateScanCodes(strokes);
var code = processedState.Code;
var state = processedState.State;
Expand All @@ -65,8 +67,16 @@ public override void ProcessStroke(List<ManagedWrapper.Stroke> strokes)
if (SingleButtonMappings.ContainsKey(code))
{
isKeyMapping = true;
useExtendedCallback = false;
mapping = SingleButtonMappings[code];
}
// If there is an mapping (via SubscribeKeyEx) to this specific key, then use that ...
if (SingleButtonMappingsEx.ContainsKey(code))
{
isKeyMapping = true;
useExtendedCallback = true;
mapping = SingleButtonMappingsEx[code];
}
// ... otherwise, if there is a mapping to the whole keyboard, use that
else if (AllButtonsMapping != null)
{
Expand All @@ -82,7 +92,14 @@ public override void ProcessStroke(List<ManagedWrapper.Stroke> strokes)
{
if (isKeyMapping)
{
ThreadPool.QueueUserWorkItem(threadProc => mapping.Callback(state));
if (useExtendedCallback)
{
ThreadPool.QueueUserWorkItem(threadProc => mapping.Callback(state, code));
}
else
{
ThreadPool.QueueUserWorkItem(threadProc => mapping.Callback(state));
}
}
else
{
Expand All @@ -94,7 +111,14 @@ public override void ProcessStroke(List<ManagedWrapper.Stroke> strokes)
//mapping.Callback(code, state);
if (isKeyMapping)
{
WorkerThreads[code]?.Actions.Add(() => mapping.Callback(state));
if (useExtendedCallback)
{
WorkerThreads[code]?.Actions.Add(() => mapping.Callback(state, code));
}
else
{
WorkerThreads[code]?.Actions.Add(() => mapping.Callback(state));
}
}
else
{
Expand Down