-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecord.au3
More file actions
executable file
·150 lines (123 loc) · 4.71 KB
/
Record.au3
File metadata and controls
executable file
·150 lines (123 loc) · 4.71 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
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
#cs
(c) 2012 Gijs van der Ent
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#ce
HotKeySet("{HOME}", "Start") ; Toggle recording mouse movements. Should not be neccessary.
HotKeySet("{END}", "Finish") ; Exit the recording script
HotKeySet("{PRINTSCREEN}", "WriteMouseMove") ; Move the mouse to the current position
HotKeySet("{NUMPAD1}", "LeftClick") ; Record a left click, but not the location
HotKeySet("{NUMPAD2}", "RightClick") ; Record a right click, but not the location
HotKeySet("{NUMPAD4}", "MoveLeftClick") ; Record a left click at the location
HotKeySet("{NUMPAD5}", "MoveRightClick") ; Record a right click at the location
HotKeySet("{NUMPAD7}", "TopLeft") ; Record the top left of a rectangle
HotKeySet("{NUMPAD8}", "BottomRight") ; Record the bottom right of a rectangle
HotKeySet("{NUMPAD9}", "RecordColor") ; Record the color at a location
Global $file = FileOpen("MouseTrackOut.au3", 2)
; Globals related to continuous mouse movement and speed.
; The idea is that mouse speed should vary depending on distance
; travelled in the interval, so speed seems natural.
Global $recordInterval = 100
Global $speedFactor = 120
Global $minSpeed = 100
Global $maxSpeed = 5
; Note that this version is programmed to record window local coordinates.
; This can be changed by removing/altering the following lines.
Opt("MouseCoordMode", 2)
FileWriteLine($file, 'Opt("MouseCoordMode", 2)')
; Global state variables
Global $exit = 0 ; Exit the script
Global $stop = 0 ; Stop recording
Global $title = ""
Global $previousPos[2] = [ -1, -1 ] ; For calculating speed in continuous move mode, may become a problem with relative coords
Global $topLeft[2] = [ -1, -1 ]
Func Start()
HotKeySet("{HOME}", "End")
FileWriteLine($file, "; Starting recording")
$stop = 0
While $stop == 0
WriteMouseMove()
Sleep($recordInterval)
WEnd
EndFunc
Func End()
$stop = 1
HotKeySet("{HOME}", "Start")
EndFunc
Func SetActiveWindow()
Local $newTitle = WinGetTitle("[active]")
If $title <> $newTitle Then
$title = $newTitle
FileWriteLine($file, 'WinActivate("' & $title & '")')
FileWriteLine($file, 'WinWaitActive("' & $title & '")')
EndIf
EndFunc
Func RecordColor()
Local $pos = MouseGetPos()
Local $color = PixelGetColor($pos[0], $pos[1])
FileWriteLine($file, ";pos: [" & $pos[0] & ", " & $pos[1] & "] color: " & Hex($color, 6))
EndFunc
Func TopLeft()
$topLeft = MouseGetPos()
EndFunc
Func BottomRight()
Local $bottomRight = MouseGetPos()
FileWriteLine($file, "MouseClick('left', Random(" & $topLeft[0] & ", " & $bottomRight[0] & "), Random(" & $topLeft[1] & ", " & $bottomRight[1] & "), Random(7, 19))")
EndFunc
Func WriteMouseMove()
SetActiveWindow()
Local $pos = MouseGetPos()
FileWriteLine($file, "MouseMove(" & $pos[0] & ", " & $pos[1] & ", " & CalculateSpeed($pos) & ")")
EndFunc
Func CalculateSpeed($pos)
Local $result = 10
If $previousPos[0] <> -1 Then
Local $distance = Sqrt((($previousPos[0] - $pos[0]) ^ 2) + (($previousPos[1] - $pos[1]) ^ 2))
$result = 100 - $speedFactor * $distance / $recordInterval
If $result > 100 Then
$result = 100
ElseIf $result < 5 Then
$result = 5
EndIf
EndIf
$previousPos = $pos
Return $result
EndFunc
Func LeftClick()
SetActiveWindow()
MouseClick("left")
FileWriteLine($file, 'MouseClick("left")')
EndFunc
Func RightClick()
SetActiveWindow()
MouseClick("right")
FileWriteLine($file, 'MouseClick("right")')
EndFunc
Func MoveLeftClick()
SetActiveWindow()
Local $pos = MouseGetPos()
MouseClick("left")
FileWriteLine($file, 'MouseClick("left", ' & $pos[0] & ", " & $pos[1] & ")")
EndFunc
Func MoveRightClick()
SetActiveWindow()
Local $pos = MouseGetPos()
MouseClick("right")
FileWriteLine($file, 'MouseClick("right", ' & $pos[0] & ", " & $pos[1] & ")")
EndFunc
Func Finish()
$exit = 1
EndFunc
; Loop until we need to exit
While $exit == 0
Sleep(1000)
WEnd
FileClose($file)