-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeylistener.pde
executable file
·211 lines (179 loc) · 4.74 KB
/
Keylistener.pde
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
Window staticWindow;
Window appWindow;
Process currentGame;
Field globalHandle;
int pid;
int lastTimeCheck;
int timeIntervalFlag = 2000;
public class JIntellitypeTester extends JFrame implements HotkeyListener {
public void onHotKey(int aIdentifier)
{
exitCurrentGame(aIdentifier);
}
public void exitCurrentGame()
{
exitCurrentGame(1);
}
void exitCurrentGame(int aIdentifier)
{
if (aIdentifier == 1)
{
loop();
dataManager.killGame(theme.currentSelection);
gameIsRunning = false;
println("just attempted to kill game");
WinDef.HWND hwnd = User32.INSTANCE.FindWindow (null, "ArcadeMenu"); // window title
if (hwnd == null) {
System.out.println("CANT FIND MY WINDOW");
}
else
{
User32.INSTANCE.ShowWindow(hwnd, 9 ); // SW_RESTORE
User32.INSTANCE.SetForegroundWindow(hwnd); // bring to front
}
}
}
}
long countero = 0;
void manageTopWindow()
{
if ( millis() > lastTimeCheck + timeIntervalFlag )
{
System.out.println("checkin " + countero );
countero++;
if(gameIsRunning)
{
ensureGameIsOnTop();
}
else
{
ensureMenuIsOnTop();
}
lastTimeCheck += timeIntervalFlag;
}
}
void ensureGameIsOnTop()
{
fill(255);
ellipse(10,10,20,20);
println("ensuring game is on top");
appWindow = staticWindow.getProcessWindow(pid);
if(appWindow == null)
{
println("Want to show game window, but game window is null");
// ==================
loop();
dataManager.killGame(theme.currentSelection);
gameIsRunning = false;
// ==================
}
else if(appWindow.getProcessID() != staticWindow.getForegroundWindow().getProcessID())
{
println("NOT ON TOP! SETTING NOW" + appWindow.getProcessID());
appWindow.maximize();
appWindow.setForeground();
}
println("just set foreground");
}
void ensureMenuIsOnTop()
{
println("ensuring menu is on top");
Window menu = staticWindow.findWindow(null, "ArcadeMenu");
if(menu.getProcessID() != staticWindow.getForegroundWindow().getProcessID())
{
println("menu not on top, setting to foreground");
menu.setForeground();
menu.maximize();
}
}
float kRelease = 0;
void keyPressed()
{
println(millis() + " " + key);
if(millis()-kRelease <200)return;
else kRelease = millis();
if(instructionsUp)
{
if(key == 'w' || key == 's')
instructionsSelection = !instructionsSelection;
}
if (!instructionsUp && (key == 'w' || key == 's') )
{
transition = true;
theme.transition = true; // Tell Program that you are transitioning to next video
if (key == 'w')
{
theme.dir = -1; //UPS
dir = -1;
}
if (key == 's')
{
theme.dir = 1; //DOWN
dir = 1;
}
}
if (keyCode == UP)
{
if(instructionsUp)
{
if(instructionsSelection)
{
drawLoadingMessage();
launchApplication();
instructionsUp = false;
}
else
{
instructionsUp = false;
}
}
else
{
instructionsUp = true;
}
}
}
void launchApplication()
{
try
{
dataManager.launchGame(theme.currentSelection);
gameIsRunning = true;
if (currentGame.getClass().getName().equals("java.lang.Win32Process") || currentGame.getClass().getName().equals("java.lang.ProcessImpl")) {
/* determine the pid on windows plattforms */
try {
globalHandle = currentGame.getClass().getDeclaredField("handle");
globalHandle.setAccessible(true);
long handl = globalHandle.getLong(currentGame);
Kernel32 kernel = Kernel32.INSTANCE;
WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(handl));
pid = kernel.GetProcessId(handle);
appWindow = staticWindow.getProcessWindow(pid);
println("Detected pid: " + pid);
// ensureGameIsOnTop();
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
catch(Exception ex)
{
}
}
void initGlobalKeyListener()
{
try {
// Initialize JIntellitype
JIntellitype.getInstance();
JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, 'B');
JIntellitype.getInstance().addHotKeyListener(mainFrame);
println("JIntellitype initialized");
}
catch (RuntimeException ex)
{
println("Either you are not on Windows, or there is a problem with the JIntellitype library!");
}
}