Fix AhiScanCodeTester.ahk

pull/84/head
Clive Galway 2 years ago
parent 29a9fbcf2f
commit 327a87bcb4

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using AutoHotInterception.Helpers;
namespace AutoHotInterception
@ -9,12 +10,13 @@ namespace AutoHotInterception
Tool to check Scan Codes and Press / Release states
Note that these are raw scancodes and states as they come from Interception. Some keys (eg extended code keys) will not match AHK key codes!
*/
public class ScanCodeChecker
public class ScanCodeChecker : IDisposable
{
private readonly IntPtr _deviceContext;
private dynamic _callback;
private int _deviceId;
private bool _block;
private Thread _pollThread;
public ScanCodeChecker()
{
@ -27,6 +29,12 @@ namespace AutoHotInterception
_deviceId = deviceId;
_block = block;
_pollThread = new Thread(PollThread);
_pollThread.Start();
}
private void PollThread()
{
ManagedWrapper.SetFilter(_deviceContext, IsMonitoredDevice, ManagedWrapper.Filter.All);
int deviceId1;
int deviceId2;
@ -45,7 +53,7 @@ namespace AutoHotInterception
strokes.Add(stroke2);
}
}
if (!block)
if (!_block)
{
for (int i = 0; i < strokes.Count; i++)
{
@ -53,10 +61,12 @@ namespace AutoHotInterception
ManagedWrapper.Send(_deviceContext, _deviceId, ref stroke, 1);
}
}
var keyEvents = new List<KeyEvent>();
foreach (var s in strokes)
// Use array for callback, as the callback may be AHK code, and dealing with arrays in AHK is way simpler that Lists
var keyEvents = new KeyEvent[strokes.Count];
for (int i = 0; i < strokes.Count; i++)
{
keyEvents.Add(new KeyEvent { Code = s.key.code, State = s.key.state });
var s = strokes[i];
keyEvents[i] = new KeyEvent { Code = s.key.code, State = s.key.state };
}
_callback(keyEvents);
}
@ -71,7 +81,12 @@ namespace AutoHotInterception
private int IsMonitoredDevice(int device)
{
return (Convert.ToInt32(_deviceId == device) );
//return (Convert.ToInt32(_deviceId == device || device == 12) );
}
public void Dispose()
{
_pollThread.Abort();
_pollThread.Join();
}
}

@ -14,9 +14,10 @@ namespace TestApp
//var kmt = new KeyboardAndMouseTester(TestDevices.WyseKeyboard, true).AddDevice(TestDevices.LogitechWheelMouse, true);
//var kkt = new KeyboardKeyTester(TestDevices.WyseKeyboard, AhkKeys.Obj("1"), true);
//var tt = new TabletTester(TestDevices.ParbloIslandA609);
var sct = 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();
}
}
}

@ -5,17 +5,23 @@ using AutoHotInterception;
namespace TestApp
{
public class ScanCodeTester
public class ScanCodeTester : IDisposable
{
private ScanCodeChecker scc;
public ScanCodeTester(TestDevice device, bool block = false)
{
var scc = new ScanCodeChecker();
scc = new ScanCodeChecker();
var devId = device.GetDeviceId();
if (devId == 0) return;
scc.Subscribe(devId, new Action<List<KeyEvent>>(OnKeyEvent), block);
scc.Subscribe(devId, new Action<KeyEvent[]>(OnKeyEvent), block);
}
public void OnKeyEvent(List<KeyEvent> keyEvents)
public void Dispose()
{
scc.Dispose();
}
public void OnKeyEvent(KeyEvent[] keyEvents)
{
var str = "";
foreach (var keyEvent in keyEvents)

@ -21,6 +21,7 @@ then the Extended Modifier key (LShift with a state of 2 in the above example) w
Similar to the above example, if you sent Home, previously, only Home would be sent with a state of 2
LShift would not have been sent with a state of 2 as it should
Also, Pause should send a state of 4, whereas before it sent a state of 2
- AhiScanCodeTester.ahk in Development Tools now works again
## [0.7.0] - 2022-01 -17
### Added

@ -15,15 +15,20 @@ Note that for some keys (eg Pause), AHI will see TWO key events for that key, he
All ScanCodes are in Decimal
*/
#include ..\Lib\AutoHotInterception.ahk
AHI := new AutoHotInterception()
vid := 0x04F2, pid := 0x0112 ; Wyse Keyboard
keyboardId := AHI.GetKeyboardId(vid, pid)
OutputDebug, DBGVIEWCLEAR
AhkKeyBuffer := []
asm := CLR_LoadLibrary("..\Lib\AutoHotInterception.dll")
sct := asm.CreateInstance("AutoHotInterception.ScanCodeChecker")
sct.Subscribe(vid, pid, Func("AhiKeyEvent"))
sct.Subscribe(keyboardId, Func("AhiKeyEvent"), false)
ih := InputHook()
ih.KeyOpt("{All}", "SN")
@ -66,7 +71,7 @@ AhiKeyEvent(keyEvents){
}
; Note that keyEvents is a ZERO-BASED array!
ahiSc1 := keyEvents[0].Code
ahiState1 := keyEvents[0].state

Loading…
Cancel
Save