|
|
@ -16,7 +16,7 @@ public class InterceptionWrapper
|
|
|
|
|
|
|
|
|
|
|
|
private readonly bool _filterState = false;
|
|
|
|
private readonly bool _filterState = false;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<int, List<Mapping>> _mappings = new Dictionary<int, List<Mapping>>();
|
|
|
|
private readonly Dictionary<int, Dictionary<ushort, Mapping>> _mappings = new Dictionary<int, Dictionary<ushort, Mapping>>();
|
|
|
|
private readonly Dictionary<int, dynamic> _contextCallbacks = new Dictionary<int, dynamic>();
|
|
|
|
private readonly Dictionary<int, dynamic> _contextCallbacks = new Dictionary<int, dynamic>();
|
|
|
|
// If a the ID of a device exists as a key in this Dictionary, then that device is filtered.
|
|
|
|
// If a the ID of a device exists as a key in this Dictionary, then that device is filtered.
|
|
|
|
// Used by IsMonitoredKeyboard
|
|
|
|
// Used by IsMonitoredKeyboard
|
|
|
@ -50,7 +50,7 @@ public class InterceptionWrapper
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool SubscribeKey(uint code, bool block, dynamic callback, int vid = 0, int pid = 0)
|
|
|
|
public bool SubscribeKey(ushort code, bool block, dynamic callback, int vid = 0, int pid = 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SetFilterState(false);
|
|
|
|
SetFilterState(false);
|
|
|
|
var id = 0;
|
|
|
|
var id = 0;
|
|
|
@ -62,10 +62,10 @@ public class InterceptionWrapper
|
|
|
|
if (id == 0) return false;
|
|
|
|
if (id == 0) return false;
|
|
|
|
if (!_mappings.ContainsKey(id))
|
|
|
|
if (!_mappings.ContainsKey(id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_mappings.Add(id, new List<Mapping>());
|
|
|
|
_mappings.Add(id, new Dictionary<ushort, Mapping>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_mappings[id].Add(new Mapping() { code = Convert.ToUInt16(code), block = block, callback = callback });
|
|
|
|
_mappings[id].Add(code, new Mapping() { block = block, callback = callback });
|
|
|
|
_filteredDevices[id] = true;
|
|
|
|
_filteredDevices[id] = true;
|
|
|
|
|
|
|
|
|
|
|
|
SetFilterState(true);
|
|
|
|
SetFilterState(true);
|
|
|
@ -73,10 +73,10 @@ public class InterceptionWrapper
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendKeyEvent(int key, int state, int device = 1)
|
|
|
|
public void SendKeyEvent(ushort key, int state, int device = 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var stroke = new Stroke();
|
|
|
|
var stroke = new Stroke();
|
|
|
|
stroke.key.code = (ushort)key;
|
|
|
|
stroke.key.code = key;
|
|
|
|
stroke.key.state = (ushort)(1 - state);
|
|
|
|
stroke.key.state = (ushort)(1 - state);
|
|
|
|
Send(_deviceContext, device, ref stroke, 1);
|
|
|
|
Send(_deviceContext, device, ref stroke, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -182,16 +182,23 @@ public class InterceptionWrapper
|
|
|
|
if (isMonitoredKeyboard)
|
|
|
|
if (isMonitoredKeyboard)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Process Subscription Mode
|
|
|
|
// Process Subscription Mode
|
|
|
|
foreach (var mapping in _mappings[i])
|
|
|
|
var code = stroke.key.code;
|
|
|
|
|
|
|
|
var state = stroke.key.state;
|
|
|
|
|
|
|
|
if (state > 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
code += 256;
|
|
|
|
|
|
|
|
state -= 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_mappings[i].ContainsKey(code))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (stroke.key.code != mapping.code) continue;
|
|
|
|
|
|
|
|
hasSubscription = true;
|
|
|
|
hasSubscription = true;
|
|
|
|
|
|
|
|
var mapping = _mappings[i][code];
|
|
|
|
if (mapping.block)
|
|
|
|
if (mapping.block)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
block = true;
|
|
|
|
block = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mapping.callback(1 - stroke.key.state);
|
|
|
|
mapping.callback(1 - state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If this key had no subscriptions, but Context Mode is set for this keyboard...
|
|
|
|
// If this key had no subscriptions, but Context Mode is set for this keyboard...
|
|
|
|
// ... then set the Context before sending the key
|
|
|
|
// ... then set the Context before sending the key
|
|
|
|