-
Notifications
You must be signed in to change notification settings - Fork 6
/
Simple Mouse Clicker.ahk
178 lines (143 loc) · 4.95 KB
/
Simple Mouse Clicker.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
#NoEnv
#NoTrayIcon
#SingleInstance ignore
SendMode Input
SetWorkingDir %A_ScriptDir%
ScriptName := "Simple Mouse Clicker"
ScriptVersion := "1.1.1.0"
CopyrightNotice := "Copyright (c) 2019 Chaohe Shi"
ConfigDir := A_AppData . "\" . ScriptName
ConfigFile := ConfigDir . "\" . ScriptName . ".ini"
; set script texts
TEXT_ClickInterval := "Click Interval"
TEXT_Hours := "Hours"
TEXT_Minutes := "Minutes"
TEXT_Seconds := "Seconds"
TEXT_MilliSeconds := "MilliSeconds"
TEXT_MouseAction := "Mouse Action"
TEXT_Button := "Button"
TEXT_Action := "Action"
TEXT_PrimaryButton := "Primary Button"
TEXT_SecondaryButton := "Secondary Button"
TEXT_SingleClick := "Single Click"
TEXT_DoubleClick := "Double Click"
TEXT_HotKey := "Hot Key"
TEXT_Start := "Start"
TEXT_Stop := "Stop"
; retrieve scipt settings
IniRead, Hours, %ConfigFile%, ClickInterval, Hours, 0
IniRead, Minutes, %ConfigFile%, ClickInterval, Minutes, 0
IniRead, Seconds, %ConfigFile%, ClickInterval, Seconds, 1
IniRead, MilliSeconds, %ConfigFile%, ClickInterval, MilliSeconds, 0
IniRead, MouseButton, %ConfigFile%, MouseAction, MouseButton, 1
IniRead, ClickAction, %ConfigFile%, MouseAction, ClickAction, 1
IniRead, HotkeyStart, %ConfigFile%, HotKey, HotkeyStart, F9
IniRead, HotkeyStop, %ConfigFile%, HotKey, HotkeyStop, F10
CurrentHotkeyStart := HotkeyStart
CurrentHotkeyStop := HotkeyStop
if (CurrentHotkeyStart != "")
{
Hotkey, %CurrentHotkeyStart%, ButtonStart, On
}
if (CurrentHotkeyStop != "")
{
Hotkey, %CurrentHotkeyStop%, ButtonStop, On
}
Gui, New, +AlwaysOnTop +HwndGuiHwnd, %ScriptName%
Gui, %GuiHwnd%:Default
Gui, Add, Tab3, , %TEXT_ClickInterval%|%TEXT_MouseAction%|%TEXT_HotKey%
Gui, Tab, 1
Gui, Add, Text, Section, %TEXT_Hours%
Gui, Add, Edit, Number Limit2 w50
Gui, Add, UpDown, vUpDownHour Range0-24, %Hours%
Gui, Add, Text, Section ys, %TEXT_Minutes%
Gui, Add, Edit, Number Limit2 w50
Gui, Add, UpDown, vUpDownMinute Range0-59, %Minutes%
Gui, Add, Text, Section ys, %TEXT_Seconds%
Gui, Add, Edit, Number Limit2 w50
Gui, Add, UpDown, vUpDownSecond Range0-59, %Seconds%
Gui, Add, Text, Section ys, %TEXT_MilliSeconds%
Gui, Add, Edit, Number Limit3 w50
Gui, Add, UpDown, vUpDownMilliSecond Range0-999, %MilliSeconds%
Gui, Tab, 2
Gui, Add, Text, Section, %TEXT_Button%
Gui, Add, Text, , %TEXT_Action%
Gui, Add, DropDownList, AltSubmit Choose%MouseButton% ys vChoiceButton, %TEXT_PrimaryButton%|%TEXT_SecondaryButton%
Gui, Add, DropDownList, AltSubmit Choose%ClickAction% vChoiceAction, %TEXT_SingleClick%|%TEXT_DoubleClick%
Gui, Tab, 3
Gui, Add, Text, Section, %TEXT_Start%
Gui, Add, Text, , %TEXT_Stop%
Gui, Add, Hotkey, Limit1 ys vHotkeyStart gHotkeyStart, %CurrentHotkeyStart%
Gui, Add, Hotkey, Limit1 vHotkeyStop gHotkeyStop, %CurrentHotkeyStop%
Gui, Tab
Gui, Add, Button, Default w75 h23 vButtonStart gButtonStart, %TEXT_Start%
GuiControl, Focus, ButtonStart
Gui, Add, Button, x+m w75 h23 vButtonStop gButtonStop, %TEXT_Stop%
GuiControl, Disable, ButtonStop
Gui, Show
Return ; end of the auto-execute section
ButtonStart:
GuiControlGet, IsEnabled, %GuiHwnd%:Enabled, ButtonStart ; check if the start button is enabled
if (IsEnabled)
{
GuiControl, %GuiHwnd%:Disable, ButtonStart
Gui, %GuiHwnd%:Submit, NoHide
Gui, Minimize
if (UpDownHour || UpDownMinute || UpDownSecond || UpDownMilliSecond) ; if click interval is not 0
{
SetTimer, % "Click" . (ChoiceButton == 2 ? "SecondaryButton" : "PrimaryButton"), % UpDownHour*3600000+UpDownMinute*60000+UpDownSecond*1000+UpDownMilliSecond
}
GuiControl, %GuiHwnd%:+Default, ButtonStop
GuiControl, %GuiHwnd%:Enable, ButtonStop
}
Return
ButtonStop:
GuiControl, %GuiHwnd%:Disable, ButtonStop
SetTimer, ClickPrimaryButton, Off
SetTimer, ClickSecondaryButton, Off
GuiControl, %GuiHwnd%:+Default, ButtonStart
GuiControl, %GuiHwnd%:Enable, ButtonStart
Return
ClickPrimaryButton:
Click, %ChoiceAction%
Return
ClickSecondaryButton:
Click, %ChoiceAction%, Right
Return
HotkeyStart:
if (CurrentHotkeyStart != "")
{
Hotkey, %CurrentHotkeyStart%, ButtonStart, Off
}
if (StrLen(StrSplit(HotkeyStart, A_Space, "^!+")[1]) > 0) ; if entered a valid hotkey
{
CurrentHotkeyStart := HotkeyStart
Hotkey, %CurrentHotkeyStart%, ButtonStart, On
}
Return
HotkeyStop:
if (CurrentHotkeyStop != "")
{
Hotkey, %CurrentHotkeyStop%, ButtonStop, Off
}
if (StrLen(StrSplit(HotkeyStop, A_Space, "^!+")[1]) > 0) ; if entered a valid hotkey
{
CurrentHotkeyStop := HotkeyStop
Hotkey, %CurrentHotkeyStop%, ButtonStop, On
}
Return
GuiClose:
Gui, %GuiHwnd%:Submit
if (!InStr(FileExist(ConfigDir), "D"))
{
FileCreateDir, %ConfigDir%
}
IniWrite, %UpDownHour%, %ConfigFile%, ClickInterval, Hours
IniWrite, %UpDownMinute%, %ConfigFile%, ClickInterval, Minutes
IniWrite, %UpDownSecond%, %ConfigFile%, ClickInterval, Seconds
IniWrite, %UpDownMilliSecond%, %ConfigFile%, ClickInterval, MilliSeconds
IniWrite, %ChoiceButton%, %ConfigFile%, MouseAction, MouseButton
IniWrite, %ChoiceAction%, %ConfigFile%, MouseAction, ClickAction
IniWrite, %HotkeyStart%, %ConfigFile%, HotKey, HotkeyStart
IniWrite, %HotkeyStop%, %ConfigFile%, HotKey, HotkeyStop
ExitApp