Add sub/unsub functionality to KeyboardAndMouseTester

wait-with-timeout-zero
Clive Galway 2 years ago
parent 339d51f573
commit 6067b4dac5

@ -14,6 +14,8 @@ namespace TestApp
public class KeyboardAndMouseTester
{
private Manager im = new Manager();
private Dictionary<int, bool> _deviceStates = new Dictionary<int, bool>();
private Dictionary<int, bool> _blockingEnabled = new Dictionary<int, bool>();
public KeyboardAndMouseTester(TestDevice testDevice, bool block = false)
{
@ -25,23 +27,56 @@ namespace TestApp
var devId = testDevice.GetDeviceId();
if (devId == 0) return this;
_blockingEnabled[devId] = block;
SetDeviceState(devId, true);
return this;
}
private void SetDeviceState(int devId, bool state)
{
if (devId < 11)
{
im.SubscribeKeyboard(devId, block, new Action<ushort, int>((code, value) =>
if (state)
{
var keyObj = AhkKeys.Obj(code);
im.SubscribeKeyboard(devId, _blockingEnabled[devId], new Action<ushort, int>((code, value) =>
{
var keyObj = AhkKeys.Obj(code);
Console.WriteLine($"Name: {keyObj.Name}, Code: {keyObj.LogCode()}, State: {value}");
}));
Console.WriteLine($"Name: {keyObj.Name}, Code: {keyObj.LogCode()}, State: {value}");
}));
}
else
{
im.UnsubscribeKeyboard(devId);
}
}
else
{
im.SubscribeMouseMove(devId, block, new Action<int, int>((x, y) =>
if (state)
{
im.SubscribeMouseMove(devId, _blockingEnabled[devId], new Action<int, int>((x, y) =>
{
Console.WriteLine($"Mouse Move: x: {x}, y: {y}");
}));
}
else
{
Console.WriteLine($"Mouse Move: x: {x}, y: {y}");
}));
im.UnsubscribeMouseMove(devId);
}
}
_deviceStates[devId] = state;
}
// Allows toggling on and off of keyboard subscription whilst mouse sub active
public void Toggle(TestDevice testDevice)
{
var devId = testDevice.GetDeviceId();
while (true)
{
Console.WriteLine($"Subscribe: {_deviceStates[devId]} (Enter to toggle)");
Console.ReadLine();
SetDeviceState(devId, !_deviceStates[devId]);
}
return this;
}
}
}

@ -11,13 +11,13 @@ namespace TestApp
//var mbt = new MouseButtonTester(TestDevices.LogitechWheelMouse, MouseButtons.Left, true);
//var ambt = new MouseButtonsTester(TestDevices.LogitechWheelMouse, true);
//var kt = new KeyboardTester(TestDevices.WyseKeyboard, true);
//var kmt = new KeyboardAndMouseTester(TestDevices.WyseKeyboard, true).AddDevice(TestDevices.LogitechWheelMouse, true);
var kmt = new KeyboardAndMouseTester(TestDevices.WyseKeyboard, true).AddDevice(TestDevices.LogitechWheelMouse, true);
kmt.Toggle(TestDevices.WyseKeyboard);
//var kkt = new KeyboardKeyTester(TestDevices.WyseKeyboard, AhkKeys.Obj("1"), true);
//var tt = new TabletTester(TestDevices.ParbloIslandA609);
var scc = new ScanCodeTester(TestDevices.WyseKeyboard, true);
//var scc = new ScanCodeTester(TestDevices.WyseKeyboard, true);
//var sst = new SetStateTester(TestDevices.WyseKeyboard, AhkKeys.Obj("1"));
Console.ReadLine();
scc.Dispose();
}
}
}

@ -0,0 +1,58 @@
#SingleInstance force
;~ #Persistent
#include Lib\AutoHotInterception.ahk
;~ pk := GetKeySC("Pause")
;~ dk := GetKeySC("Delete")
;~ RCtrl := GetKeySC("RCtrl")
msgbox % GetKeySC("ScrollLock")
;~ return
;~ msgbox % Format("{:d}", GetKeySC("Pause"))
return
clipboard := ""
log := "`n// ============ DUPES ==================`n"
keys := {}
Loop 512 {
hex := Format("{:x}", A_Index)
name := GetKeyName("sc" hex)
if (name == "")
continue
str := "{" A_Index " /*(0x" hex ")*/, " """" name """" "}"
;~ if (A_Index == 86 || A_Index = 342)
;~ break = true
if (keys.HasKey(name)){
log .= "// " str " (Also " keys[name] ")`n"
} else {
clipboard .= str ",`n"
keys[name] := A_Index
}
}
clipboard .= log
return
state := true
AHI := new AutoHotInterception()
;~ keyboardId := AHI.GetKeyboardId(0x04F2, 0x0112)
;~ AHI.SubscribeKey(keyboardId, GetKeySC("1"), true, Func("KeyEvent"))
mouseId := AHI.GetMouseId(0x046D, 0xC00C)
AHI.SubscribeMouseMove(mouseId, true, Func("OnMouseMove"))
return
KeyEvent(state){
ToolTip % "State: " state
}
OnMouseMove(x, y){
Tooltip % x ", " y, 0, 0
}
F1::
state := !state
AHI.SetState(state)
Tooltip
return
^Esc::
ExitApp
Loading…
Cancel
Save