-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeHook.bas
More file actions
81 lines (70 loc) · 2.43 KB
/
NativeHook.bas
File metadata and controls
81 lines (70 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=8.9
@EndOfDesignText@
Sub Class_Globals
Private globalScreen As JavaObject
Private mCallBack As Object 'ignore
Private mEventName As String 'ignore
Private listener As JavaObject
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Callback As Object, EventName As String)
mCallBack = Callback
mEventName = EventName
globalScreen.InitializeStatic("com.github.kwhat.jnativehook.GlobalScreen")
globalScreen.RunMethod("registerNativeHook",Null)
Dim jo As JavaObject = Me
listener = jo.RunMethod("newInstance",Null)
globalScreen.RunMethod("addNativeKeyListener",Array(listener))
End Sub
Public Sub cleanup
globalScreen.RunMethod("removeNativeKeyListener",Array(listener))
globalScreen.RunMethod("unregisterNativeHook",Null)
End Sub
public Sub getKeyCode(e As JavaObject) As String
Return e.RunMethod("getKeyCode",Null)
End Sub
private Sub nativeKeyPressed(e As Object)
If SubExists(mCallBack,mEventName&"_NativeKeyPressed") Then
CallSubDelayed2(mCallBack,mEventName&"_NativeKeyPressed",getKeyCode(e))
End If
End Sub
private Sub nativeKeyTyped(e As Object)
If SubExists(mCallBack,mEventName&"_NativeKeyTyped") Then
CallSubDelayed2(mCallBack,mEventName&"_NativeKeyTyped",getKeyCode(e))
End If
End Sub
private Sub nativeKeyReleased(e As Object)
If SubExists(mCallBack,mEventName&"_NativeKeyReleased") Then
CallSubDelayed2(mCallBack,mEventName&"_NativeKeyReleased",getKeyCode(e))
End If
End Sub
#If Java
import com.github.kwhat.jnativehook.NativeHookException;
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
public GlobalKeyListenerExample newInstance(){
return new GlobalKeyListenerExample();
}
public class GlobalKeyListenerExample implements NativeKeyListener {
public void nativeKeyPressed(NativeKeyEvent e) {
if (ba.subExists("nativekeypressed")) {
ba.raiseEvent2(null, true, "nativekeypressed", false, e);
}
}
public void nativeKeyReleased(NativeKeyEvent e) {
if (ba.subExists("nativekeyreleased")) {
ba.raiseEvent2(null, true, "nativekeyreleased", false, e);
}
}
public void nativeKeyTyped(NativeKeyEvent e) {
//System.out.println("Key Typed: " + e.getKeyText(e.getKeyCode()));
if (ba.subExists("nativekeytyped")) {
ba.raiseEvent2(null, true, "nativekeytyped", false, e);
}
}
}
#End If