forked from histefanhere/XAHK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxahk.ahk
332 lines (308 loc) · 10.6 KB
/
xahk.ahk
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
;==================================================================================================
; AHK setting
#NoEnv
SetBatchLines -1
SetTitleMatchMode 2
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
;==================================================================================================
; Globle values
wintitle := Minecraft X-AHK V0.4
targettitle := none
targetwinclass := GLFW30 ;This is the Class of a Java program used to check we have a Minecraft prog
ModeText := Empty
id := 0
ProgState := 0
;===================================================================================================
;List of ProgState's
;
; 0: Start - Program called for first time and setting default state. Hotkeys set, menu
; configured and default welcome GUI
; 1: Selected - User has selected the target window to send key/mouse activity too
; will use option Menu to slect mode. Note that JumpFlying is only
; avalible while in this state!
; 2: FishingMode - Enter Fishing Mode
; 3: ConcreteMode - Enter Concrete Mode
; 4: MobGrindMode - Enter Mob Grinder Mode
;===================================================================================================
;Shortcuts
;===================================================================================================
Hotkey !^f, Fishing ; Pressing ctrl + alt + f will start fishing
Hotkey !^e, JumpFly ; Pressing ctrl + alt + e will dubble hit space and fire a rockct in
; main hand
Hotkey !^c, Concrete ; Pressing ctrl + alt + c will start concrete farming
Hotkey !^m, MobGrind ; Pressing ctrl + alt + m will start mob grinding
Hotkey !^s, Stop ; Pressing ctrl + alt + s will stop it
Hotkey !^w, SelectWindow ;Allows user to select window to control by hovering mouse over it and
;Pressing ctrl + alt + w
;===================================================================================================
;Menu
;===================================================================================================
Menu, FileMenu, Add, Open, MenuFileOpen
Menu, FileMenu, Add, Exit, MenuHandler
Menu, HelpMenu, Add, About, MenuHandler
Menu, OptionsMenu, Add, Fishing, MenuFishing
Menu, OptionsMenu, Add, AFK Mob, MenuAFK
Menu, OptionsMenu, Add, Concrete, MenuConcrete
Menu, OptionsMenu, Add, JumpFlying, MenuJumpFly
Menu, ClickerMenu, Add, File, :FileMenu
Menu, ClickerMenu, Add, Help, :HelpMenu
Menu, ClickerMenu, Add, Options, :OptionsMenu
;===================================================================================================
;GUI-Default Welcome Screen
; Start screen asking user to select the target window to send keys to
;===================================================================================================
if %ProgState% != 0
Return
Gui, Show, w300 h300, Shortcuts
Gui, Add, Pic, w280 h290 vpic_get, welcomepic.png
Gui, Show,, Minecraft X-AHK V0.4
return
;===================================================================================================
; Called when Ctrl+Alt+W is pressed and captures target window information, checks its a java prog
;and then creates the first window.
SelectWindow:
{
;Get mouse pos on screen and grab details of program
MouseGetPos, , , id, control
WinGetTitle, targettitle, ahk_id %id%
WinGetClass, targetclass, ahk_id %id%
;MsgBox, ahk_id %id%`nahk_class %targetclass%`n%targettitle%`nControl: %control%
;Check is Class of program is a Minecraft Java Class
if InStr(targetclass, targetwinclass)
{
;Target window found, swop to next screen
ProgState = 1
Gui, Destroy
Gui, Show, w500 h500, Temp
Gui, Menu, ClickerMenu
Gui, Add, Text,, Target Window Title : %targettitle%
Gui, Add, Text,, Windows HWIND is : %id%
Gui, Add, Text,, To change mode of opperation please select from Option menu.
Gui, Add, Text,, MODE:
Gui, Add, Text, vMode w30, None
Gui, Show,, Minecraft X-AHK V0.4
;clear mouse clicks to target by sending UP to the keys
ControlClick, , ahk_id %id%, ,Right, , NAU
ControlClick, , ahk_id %id%, ,Left, ,NAU
sleep 500
}
Else
{
;Class of target program not a match so give warning message
MsgBox, You do not seam to have selected a Minecraft window. Please check before you continue.
}
Return
}
;===================================================================================================
;Menu Functions
; Place holder - will allow users to load saved values
;===================================================================================================
MenuFileOpen:
{
ModeText := JumpFlying
GuiControl,,Mode, %ModeText%
Return
}
;===================================================================================================
MenuHandler:
{
Return
}
;===================================================================================================
; Switch to Fishing mode and update window
MenuFishing:
{
; Stop and current active AHK process
BreakLoop := 1
Gui, Destroy
Gui, Show, w500 h500, Temp
Gui, Menu, ClickerMenu
Gui, Add, Text,, Target Window Title : %targettitle%
Gui, Add, Text,, Windows HWIND is : %id%
Gui, Add, Text,, CURRENT AVALIBLE OPTIONS:
Gui, Add, Text,, o- Pressing ctrl + alt + f will start fishing
Gui, Add, Text,, o- Pressing ctrl + alt + s will stop any AutoKey funtion above
Gui, Add, Text,,
Gui, Add, Slider, vMySlider w200 ToolTip Range0-1000 TickInterval100, 500
Gui, Show,, Minecraft X-AHK V0.4
ProgState := 2
Return
}
;===================================================================================================
; Switch to AFK mode and update window
MenuAFK:
{
; Stop and current active AHK process
BreakLoop := 1
Gui, Destroy
Gui, Show, w500 h500, Temp
Gui, Menu, ClickerMenu
Gui, Add, Text,, Target Window Title : %targettitle%
Gui, Add, Text,, Windows HWIND is : %id%
Gui, Add, Text,, CURRENT AVALIBLE OPTIONS:
Gui, Add, Text,, o- Pressing ctrl + alt + m will start Mod Grinding
Gui, Add, Text,, o- Pressing ctrl + alt + s will stop any AutoKey funtion above
Gui, Show,, Minecraft X-AHK V0.4
ProgState := 4
Return
}
;===================================================================================================
; Switch to Concrete mode and update window
MenuConcrete:
{
; Stop and current active AHK process
BreakLoop := 1
Gui, Destroy
Gui, Show, w500 h500, Temp
Gui, Menu, ClickerMenu
Gui, Add, Text,, Target Window Title : %targettitle%
Gui, Add, Text,, Windows HWIND is : %id%
Gui, Add, Text,, CURRENT AVALIBLE OPTIONS:
Gui, Add, Text,, o- Pressing ctrl + alt + c will start concrete farming
Gui, Add, Text,, o- Pressing ctrl + alt + s will stop any AutoKey funtion above
Gui, Show,, Minecraft X-AHK V0.4
ProgState := 3
Return
}
;===================================================================================================
; Switch to Flying mode and update window
MenuJumpFly:
{
; Stop and current active AHK process
BreakLoop := 1
Gui, Destroy
Gui, Show, w500 h500, Temp
Gui, Menu, ClickerMenu
Gui, Add, Text,, Target Window Title : %targettitle%
Gui, Add, Text,, Windows HWIND is : %id%
Gui, Add, Text,, CURRENT AVALIBLE OPTIONS:
Gui, Add, Text,, o- Pressing ctrl + alt + e will dubble hit space and fire a rocket in main hand
Gui, Show,, Minecraft X-AHK V0.4
ProgState := 1
Return
}
;===================================================================================================
; Called when Ctrl+Alt+E is pressed.
; NOTE: Target window MUST be in focus for this to work
JumpFly:
{
if (ProgState != 1)
Return
Sleep 500
Send {Space down}
Sleep 75
Send {Space up}
Sleep 200
Send {Space down}
Sleep 75
Send {Space up}
Sleep 50
ControlClick, , ahk_id %id%, ,Right, , NAD
Sleep 100
ControlClick, , ahk_id %id%, ,Right, , NAU
Return
}
;===================================================================================================
; Called when Ctrl+Alt+C is pressed. Hold both RIGHT and LEFT click down.
Concrete:
{
if (ProgState != 3)
Return
BreakLoop := 0
ControlClick, , ahk_id %id%, ,Right, , NAD
Sleep 500
ControlClick, , ahk_id %id%, ,Left, , NAD
sleep 100
While (BreakLoop = 0)
{
if BreakLoop = 1)
{
sleep 10
}
}
ControlClick, , ahk_id %id%, ,Left, , NAU
Sleep 100
ControlClick, , ahk_id %id%, ,Right, , NAU
Return
}
;===================================================================================================
; Called when Ctrl+Alt+F is pressed and continuly clicks RIGHT mouse key
Fishing:
{
if (ProgState != 2)
Return
BreakLoop := 0
Loop
{
if (BreakLoop = 1)
{
BreakLoop := 0
break
}
Sleep 100
ControlClick, , ahk_id %id%, ,Right, , NAD
Sleep 500
ControlClick, , ahk_id %id%, ,Right, , NAU
}
Return
}
;==================================================================================================
; Called when Ctrl+Alt+M is pressed
MobGrind:
{
if (ProgState != 4)
Return
BreakLoop := 0
Delay := 0
Sleep 500
While (BreakLoop = 0)
{
;on each loop send RIGHT key down as it can be lost when switching focus
ControlClick, , ahk_id %id%, ,Right, , NAD
if (BreakLoop = 1)
{
; On Ctrl+Alt+S detected forces a RIGHT mouse key UP
ControlClick, , ahk_id %id%, ,Right, , NAU
Return
}
Sleep 100 ;100 ms
;Delay between LEFT clicks is controled by sleep delay above * value tested here (ie 12)
; Example = 100ms * 12 = 1.2 seconds
;This method allows AHK to better exit this mode and respond quicker to Stop command
if (Delay >= 12)
{
; If delay counter reached, reset counter and send a LEFT click
Delay := 0
sleep 50
ControlClick, , ahk_id %id%, ,Left, ,NAD
Sleep 50
ControlClick, , ahk_id %id%, ,Left, ,NAU
}
else
Delay++ ;Increase delay counter by 1
}
Sleep 100
;Force mouse keys UP at exit
ControlClick, , ahk_id %id%, ,Right, , NAU
ControlClick, , ahk_id %id%, ,Left, ,NAU
Return
}
;==================================================================================================
; Called when Ctrl+Alt+S is pressed at ANYTIME
; By setting the globle value of 'BreakLoop' to 1 this causes any running mode to exit under its own
;control without leaving key states in correctly. Due to Mouse loss of focus STOP will also force
;mouse keys UP.
Stop:
{
BreakLoop := 1
ControlClick, , ahk_id %id%, ,Right, , NAU
ControlClick, , ahk_id %id%, ,Left, ,NAU
sleep 500
return
}
;===================================================================================================
ESC:
GuiClose:
GuiEscape:
ExitApp