diff --git a/C#/TestApp/KeyboardAndMouseTester.cs b/C#/TestApp/KeyboardAndMouseTester.cs index b6368ef..3280e34 100644 --- a/C#/TestApp/KeyboardAndMouseTester.cs +++ b/C#/TestApp/KeyboardAndMouseTester.cs @@ -14,6 +14,8 @@ namespace TestApp public class KeyboardAndMouseTester { private Manager im = new Manager(); + private Dictionary _deviceStates = new Dictionary(); + private Dictionary _blockingEnabled = new Dictionary(); 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((code, value) => + if (state) { - var keyObj = AhkKeys.Obj(code); + im.SubscribeKeyboard(devId, _blockingEnabled[devId], new Action((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((x, y) => + if (state) + { + im.SubscribeMouseMove(devId, _blockingEnabled[devId], new Action((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; } } } diff --git a/C#/TestApp/Program.cs b/C#/TestApp/Program.cs index 0c4e07e..ac4a1ef 100644 --- a/C#/TestApp/Program.cs +++ b/C#/TestApp/Program.cs @@ -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(); } } } \ No newline at end of file diff --git a/Test.ahk b/Test.ahk new file mode 100644 index 0000000..7db4d27 --- /dev/null +++ b/Test.ahk @@ -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 \ No newline at end of file