POC for handling extended keys with WaitWithTimeout of 0

pull/84/head
Clive Galway 2 years ago
parent ae06a4f1ee
commit ccb6a0f02c

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using AutoHotInterception.Helpers;
namespace AutoHotInterception
@ -29,10 +30,27 @@ namespace AutoHotInterception
ManagedWrapper.SetFilter(_deviceContext, IsMonitoredDevice, ManagedWrapper.Filter.All);
int i;
var stroke = new ManagedWrapper.Stroke();
while (ManagedWrapper.Receive(_deviceContext, i = ManagedWrapper.Wait(_deviceContext), ref stroke, 1) > 0)
while (true)
{
if (!_block) ManagedWrapper.Send(_deviceContext, _deviceId, ref stroke, 1);
_callback(new KeyEvent { Code = stroke.key.code, State = stroke.key.state });
var strokes = new List<ManagedWrapper.Stroke>();
while (ManagedWrapper.Receive(_deviceContext, i = ManagedWrapper.WaitWithTimeout(_deviceContext, 0), ref stroke, 1) > 0)
{
strokes.Add(stroke);
}
if (!block)
{
foreach (var s in strokes)
{
ManagedWrapper.Send(_deviceContext, _deviceId, ref stroke, 1);
}
}
if (strokes.Count == 0) continue;
var keyEvents = new List<KeyEvent>();
foreach (var s in strokes)
{
keyEvents.Add(new KeyEvent { Code = stroke.key.code, State = stroke.key.state });
}
_callback(keyEvents);
}
}
@ -43,7 +61,8 @@ namespace AutoHotInterception
private int IsMonitoredDevice(int device)
{
return Convert.ToInt32(_deviceId == device);
return (Convert.ToInt32(_deviceId == device) );
//return (Convert.ToInt32(_deviceId == device || device == 12) );
}
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using AutoHotInterception;
@ -11,12 +12,17 @@ namespace TestApp
var scc = new ScanCodeChecker();
var devId = device.GetDeviceId();
if (devId == 0) return;
scc.Subscribe(devId, new Action<KeyEvent>(OnKeyEvent), block);
scc.Subscribe(devId, new Action<List<KeyEvent>>(OnKeyEvent), block);
}
public void OnKeyEvent(KeyEvent keyEvent)
public void OnKeyEvent(List<KeyEvent> keyEvents)
{
Debug.WriteLine($"Code: {keyEvent.Code} (0x{keyEvent.Code.ToString("X")}) - {keyEvent.Code + 256}, State: {keyEvent.State}");
var str = $"{keyEvents.Count} - ";
foreach (var keyEvent in keyEvents)
{
str += $"Code: {keyEvent.Code} (0x{keyEvent.Code.ToString("X")}) - {keyEvent.Code + 256}, State: {keyEvent.State} | ";
}
Debug.WriteLine(str);
}
}
}

@ -12,6 +12,7 @@ namespace TestApp
public static TestDevice WyseKeyboard { get; } = new TestDevice { IsMouse = false, Vid = 0x04F2, Pid = 0x0112 };
public static TestDevice LogitechWheelMouse { get; } = new TestDevice { IsMouse = true, Vid = 0x046D, Pid = 0xC00C };
public static TestDevice ParbloIslandA609 { get; } = new TestDevice { IsMouse = true, Handle = "HID\\VID_0B57&PID_9091&REV_0101&Col01" };
public static TestDevice LogitechG604Mouse { get; } = new TestDevice { IsMouse = true, Vid = 0x046D, Pid = 0xC539 };
}
public class TestDevice

Loading…
Cancel
Save