-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyListener.java
More file actions
125 lines (87 loc) · 3.06 KB
/
KeyListener.java
File metadata and controls
125 lines (87 loc) · 3.06 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package me.AustinNotAustin.AustinsAutoClicker;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
public class KeyListener implements NativeKeyListener {
// hotkeyAction = Start
// hotkeyBinding = F9
// hotkeyAction is the button that performs and action in the main script
// hotkeyBinding is the assigned hot key to an action
private static String start = "F9";
private static String stop = "F10";
private static String activeKey = "";
// Don't think this is doing anything
String command = "";
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
// Generic message showing the action performed
System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
checkCommand(NativeKeyEvent.getKeyText(e.getKeyCode()));
activeKey = NativeKeyEvent.getKeyText(e.getKeyCode());
}
@Override
public void nativeKeyReleased(NativeKeyEvent e) {
// Generic message showing the action performed
//System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
}
@Override
public void nativeKeyTyped(NativeKeyEvent e) {
// Generic message showing the action performed
//System.out.println("Key Typed: " + e.getKeyText(e.getKeyCode()));
}
// Get's the hot key mapping assigned to the hot key action
public static String getHotkeyBinding(String hotkeyAction) {
// If the hot key action is start
if (hotkeyAction.toLowerCase() == "start") {
// Return the hot key binding
return start;
}
if (hotkeyAction.toLowerCase() == "stop") {
//Return the hot key binding
return stop;
}
System.out.println("The hot key action entered was not listed");
return null;
}
public static void setHotkeyBinding(String hotkeyAction, String hotkeyBinding) {
// If the hot key action is start
if (hotkeyAction.toLowerCase() == "start") {
// Set the new value key binding for start
start = hotkeyBinding.toUpperCase();
}
// If the hot key action is start
if (hotkeyAction.toLowerCase() == "stop") {
// Set the new value key binding for stop
stop = hotkeyBinding.toUpperCase();
}
}
public static String getActiveKey() {
if (activeKey == start)
return start;
if (activeKey == stop)
return stop;
return activeKey;
}
public static void setActiveKey(String key) {
activeKey = key;
}
public static String getResetActiveKey() {
System.out.println("getResetActiveKey() was just called, activeKey is now: " + activeKey);
String key = activeKey;
System.out.println("activeKey was just set to: " + activeKey);
if (key == start) {
activeKey = "";
return start;
}
if (key == stop) {
activeKey = "";
return stop;
}
return activeKey;
}
public static void checkCommand(String cmd) {
if (cmd == KeyListener.getHotkeyBinding("start"))
Main.callStart();
if (cmd == KeyListener.getHotkeyBinding("stop"))
Main.stopProgram();
}
}