-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.lua
188 lines (144 loc) · 3.63 KB
/
template.lua
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
--[[ Configuration --]]
SCREEN_WIDTH = 2560 --[[ Change according to your screen resolution --]]
SCREEN_HEIGHT = 1440 --[[ eg. the default value stands for 2K resolution --]]
DELAY = 200 --[[ Auto delay between each key press or mouse click in milliseconds--]]
--[[ State variable --]]
DEBUG_MODE = false --[[ In debug mode, each key press or mouse click is printed --]]
function OnEvent(event, arg)
--[[ User-defined buttons --]]
if (event == "G_RELEASED" and arg == 1) then
end
if (event == "G_RELEASED" and arg == 2) then
end
if (event == "G_RELEASED" and arg == 3) then
end
if (event == "G_RELEASED" and arg == 4) then
end
if (event == "G_RELEASED" and arg == 5) then
end
--[[ Print mouse state --]]
if (event == "G_RELEASED" and arg == 6) then
PrintMouseState()
end
--[[ Toggle debug mode --]]
if (event == "G_RELEASED" and arg == 7) then
DEBUG_MODE = not DEBUG_MODE
if (DEBUG_MODE) then
Print("Debug mode: On")
else
Print("Debug mode: Off")
end
end
--[[ Record mouse action --]]
if (event == "G_RELEASED" and arg == 8) then
x, y = GetPos()
Print("MoveToAndLeftClick(%d, %d)", x, y)
end
if (event == "G_RELEASED" and arg == 9) then
x, y = GetPos()
Print("MoveToAndRightClick(%d, %d)", x, y)
end
end
--[[ User-made macros --]]
function example()
MoveToAndLeftClick(2265, 1412)
MoveToAndRightClick(2259, 1361)
KeyPress("up", 3)
KeyPress("enter")
MoveToAndLeftClick(1141, 841)
MoveToAndLeftClick(1454, 842)
end
--[[ Mouse library --]]
function GetPos()
x, y = GetMousePosition()
x = x / 65535 * SCREEN_WIDTH
y = y / 65535 * SCREEN_HEIGHT
return x, y
end
function MoveTo(x, y)
if (DEBUG_MODE) then
Print("MoveTo(%d, %d)", x, y)
end
x = x / SCREEN_WIDTH * 65535
y = y / SCREEN_HEIGHT * 65535
MoveMouseTo(x, y)
Sleep(DELAY)
end
function LeftClick()
if (DEBUG_MODE) then
Print("LeftClick()")
end
PressAndReleaseMouseButton(1)
Sleep(DELAY)
end
function RightClick()
if (DEBUG_MODE) then
Print("RightClick()")
end
PressAndReleaseMouseButton(3)
Sleep(DELAY)
end
function MoveToAndLeftClick(x, y)
MoveTo(x, y)
LeftClick()
end
function MoveToAndRightClick(x, y)
MoveTo(x, y)
RightClick()
end
--[[ Keyboard library --]]
function KeyPress(keyname, count)
if (count == nil) then
count = 1
end
for i = 1, count, 1 do
if (DEBUG_MODE) then
Print("KeyPress(\"%s\")", keyname)
end
PressAndReleaseKey(keyname)
Sleep(DELAY)
end
end
function KeyPressModified(keyname1, keyname2, count)
if (count == nil) then
count = 1
end
for i = 1, count, 1 do
if (DEBUG_MODE) then
Print("KeyPressModified(\"%s\", \"%s\")", keyname1, keyname2)
end
PressKey(keyname1)
Sleep(DELAY / 4)
PressKey(keyname2)
Sleep(DELAY / 4)
ReleaseKey(keyname2)
Sleep(DELAY / 4)
ReleaseKey(keyname1)
Sleep(DELAY)
end
end
--[[ Other library --]]
function Print(...)
OutputLogMessage(...)
OutputLogMessage("\n")
end
function PrintMouseState()
EnablePrimaryMouseButtonEvents(true)
Print("------------------------------------------")
if (IsMouseButtonPressed(1)) then
Print("Left Mouse Button: Pressed")
else
Print("Left Mouse Button: Not Pressed")
end
if (IsMouseButtonPressed(2)) then
Print("Middle Mouse Button: Pressed")
else
Print("Middle Mouse Button: Not Pressed")
end
if (IsMouseButtonPressed(3)) then
Print("Right Mouse Button: Pressed")
else
Print("Right Mouse Button: Not Pressed")
end
Print("------------------------------------------")
end