Add UnsubscribeKey

device-handlers
Clive Galway 3 years ago
parent b08098f38b
commit 6ed28dc69c

@ -8,12 +8,36 @@ namespace AutoHotInterception.DeviceHandlers
class KeyboardHandler : DeviceHandler
{
private ConcurrentDictionary<ushort, MappingOptions> KeyboardKeyMappings = new ConcurrentDictionary<ushort, MappingOptions>();
private MappingOptions KeyboardMappings;
public KeyboardHandler(IntPtr deviceContext, int deviceId) : base (deviceContext, deviceId)
{
}
public void SubscribeKey(ushort code, MappingOptions mappingOptions)
{
KeyboardKeyMappings.TryAdd(code, mappingOptions);
if (!mappingOptions.Concurrent)
{
WorkerThreads.TryAdd(code, new WorkerThread());
WorkerThreads[code].Start();
}
}
public void UnsubscribeKey(ushort code)
{
KeyboardKeyMappings.TryRemove(code, out _);
if (KeyboardKeyMappings.Count == 0)
{
// Don't remove filter if all keys subscribed
if (KeyboardMappings != null)
{
IsFiltered = false;
}
}
}
public override void ProcessStroke(ManagedWrapper.Stroke stroke)
{
//ManagedWrapper.Send(DeviceContext, _deviceId, ref stroke, 1);
@ -93,15 +117,5 @@ namespace AutoHotInterception.DeviceHandlers
//if (!hasSubscription && hasContext) ContextCallbacks[i](0);
}
}
public void SubscribeKey(ushort code, MappingOptions mappingOptions)
{
KeyboardKeyMappings.TryAdd(code, mappingOptions);
if (!mappingOptions.Concurrent)
{
WorkerThreads.TryAdd(code, new WorkerThread());
WorkerThreads[code].Start();
}
}
}
}

@ -104,21 +104,6 @@ namespace AutoHotInterception
var handler = (KeyboardHandler)DeviceHandlers[id];
handler.SubscribeKey(code, new MappingOptions { Block = block, Concurrent = concurrent, Callback = callback });
//if (!KeyboardKeyMappings.ContainsKey(id))
// KeyboardKeyMappings.TryAdd(id, new ConcurrentDictionary<ushort, MappingOptions>());
//KeyboardKeyMappings[id].TryAdd(code,
// new MappingOptions { Block = block, Concurrent = concurrent, Callback = callback });
//if (!concurrent)
//{
// if (!WorkerThreads.ContainsKey(id))
// WorkerThreads.TryAdd(id, new ConcurrentDictionary<ushort, WorkerThread>());
// WorkerThreads[id].TryAdd(code, new WorkerThread());
// WorkerThreads[id][code].Start();
//}
SetDeviceFilterState(id, true);
SetFilterState(true);
SetThreadState(true);
@ -129,19 +114,8 @@ namespace AutoHotInterception
HelperFunctions.IsValidDeviceId(false, id);
SetFilterState(false);
if (KeyboardKeyMappings.TryGetValue(id, out var thisDevice))
{
thisDevice.TryRemove(code, out _);
if (thisDevice.Count == 0)
{
KeyboardKeyMappings.TryRemove(id, out _);
// Don't remove filter if all keys subscribed
if (!KeyboardMappings.ContainsKey(id))
{
SetDeviceFilterState(id, false);
}
}
}
var handler = (KeyboardHandler)DeviceHandlers[id];
handler.UnsubscribeKey(code);
SetFilterState(true);
SetThreadState(true);

Loading…
Cancel
Save