Skip to content

Commit fe5ebfa

Browse files
committed
SubscribeKeyboard working
1 parent 3577f5a commit fe5ebfa

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

C#/TestApp/KeyboardKeyTester.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ public KeyboardKeyTester()
1313
{
1414
var im = new Manager();
1515

16-
var devId = im.GetKeyboardId(0x03EB, 0xFF02);
16+
var devId = im.GetKeyboardId(0x04F2, 0x0112);
1717

1818
if (devId == 0) return;
1919

20-
im.SubscribeKey(devId, 0x1, false, new Action<int>(value =>
21-
{
22-
Console.WriteLine($"State: {value}");
23-
}));
20+
im.SubscribeKey(devId, 0x2, false, new Action<int>(OnKeyEvent));
2421
}
2522

2623
public void OnKeyEvent(int value)

C#/TestApp/KeyboardTester.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ public KeyboardTester()
1717

1818
if (devId == 0) return;
1919

20-
im.SubscribeKey(devId, 0x2, false, new Action<int>(value =>
21-
{
22-
Console.WriteLine($"State: {value}");
23-
}));
20+
im.SubscribeKeyboard(devId, false, new Action<ushort, int>(OnKeyEvent));
2421
}
2522

26-
public void OnKeyEvent(int value)
23+
public void OnKeyEvent(ushort code, int value)
2724
{
28-
Console.WriteLine($"State: {value}");
25+
Console.WriteLine($"Code: {code}, State: {value}");
2926
}
3027
}
3128
}

C#/TestApp/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ internal class TestApp
88
private static void Main()
99
{
1010
//var mt = new MouseTester();
11-
var kt = new KeyboardKeyTester();
11+
var kt = new KeyboardTester();
12+
//var kt = new KeyboardKeyTester();
1213
//var tt = new TabletTester();
1314
//var mon = new MonitorTester();
1415
Console.ReadLine();

Lib/AutoHotInterception.ahk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ class AutoHotInterception {
152152
this.Instance.SubscribeKey(id, code, block, callback, concurrent)
153153
}
154154

155+
SubscribeKeyboard(id, block, callback, concurrent := false) {
156+
this.Instance.SubscribeKeyboard(id, block, callback, concurrent)
157+
}
158+
155159
UnsubscribeKey(id, code){
156160
this.Instance.UnsubscribeKey(id, code)
157161
}

SubscribeAllTest.ahk

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#SingleInstance force
2+
#Persistent
3+
#include Lib\AutoHotInterception.ahk
4+
5+
AHI := new AutoHotInterception()
6+
7+
keyboardId := AHI.GetKeyboardId(0x04F2, 0x0112)
8+
AHI.SubscribeKeyboard(keyboardId, true, Func("KeyEvent"))
9+
return
10+
11+
KeyEvent(code, state){
12+
ToolTip % "Code: " code ", State: " state
13+
}
14+
15+
^Esc::
16+
ExitApp

0 commit comments

Comments
 (0)