Report abuse

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
; Set our co-ordinates relative to the active window
AutoItSetOption("MouseCoordMode", 0)
$registered = false
Dim $keys[10][2]

While 1
	If WinActive("Plants vs. Zombies") Then
		RegisterKeys()
	Else
		UnregisterKeys()
	EndIf
	Sleep(100)
WEnd

; This function selects the plant associated with the hotkey and moves
; the mouse back into the existing position.
Func SelectPlant()
	If WinActive("Plants vs. Zombies") Then
		$slot = @HotKeyPressed
		$slot -= 1;
		If $slot == -1 Then
			$slot = 9
		EndIf
		$currentPosition = MouseGetPos()
		MouseClick("primary", $keys[$slot][0], $keys[$slot][1], 1, 0)
		MouseMove($currentPosition[0], $currentPosition[1], 0)
	EndIf
EndFunc

Func RegisterKeys()
	If NOT $registered Then
		$i = 0
		$x = 114
		$y = 70
		While $i < 10
			; Add the plant position to the array
			$keys[$i][0] = $x
			$keys[$i][1] = $y
			
			; Register the hotkey for this number
			HotKeySet($i, "SelectPlant")
			
			; Increase the X value to be the next button
			$x += 52
			$i += 1
		WEnd
		$registered = true
	EndIf
EndFunc

Func UnregisterKeys()
	If $registered Then
		$i = 0
		While $i < 10
			HotKeySet($i);
			$i += 1;
		WEnd
		$registered = false
	EndIf
EndFunc