View difference between Paste ID: cgB82Bm6 and yLJEbMxP
SHOW: | | - or go back to the newest paste.
1
;Non-Intrusive Autoclicker, by Shadowspaz
2
;v2.1.1
3
4
#InstallKeybdHook
5
#SingleInstance, Force
6
DetectHiddenWindows, on
7
SetControlDelay -1
8
SetBatchLines -1
9
Thread, Interrupt, 0
10
SetFormat, float, 0.0
11
12
toggle := false
13
inputPresent := false
14
mouseMoved := false
15
settingPoints := false
16
17
clickRate := 20
18
Mode := 0
19
pmx := 0
20
pmy := 0
21
22
totalClicks := 1
23
currentClick := 1
24
25
TempRateCPS := 50
26
TempRateSPC := 1
27
28
setTimer, checkMouseMovement, 10
29
30
setTimer, setTip, 5
31
TTStart = %A_TickCount%
32
while (A_TickCount - TTStart < 5000 && !toggle)
33
{
34
  TooltipMsg = Press (Alt + Backspace) to toggle autoclicker `n Press (Alt + Dash(-)) for options
35
}
36
  TooltipMsg =
37
38
!-::
39
  IfWinNotExist, NIAC Settings
40
  {
41
    if settingPoints
42
    {
43
      toggle := false
44
      settingPoints := false
45
      actWin :=
46
      TooltipMsg =
47
    }
48
49
    prevTC := totalClicks
50
51
    Gui, Show, w210 h160, NIAC Settings
52
    Gui, Add, Radio, x25 y10 gActEdit1 vmode, Clicks per second:
53
    Gui, Add, Radio, x25 y35 gActEdit2, Seconds per click:
54
    Gui, Add, Edit, x135 y8 w50 Number Left vtempRateCPS, % tempRateCPS
55
    Gui, Add, Edit, x135 y33 w50 Number Left vtempRateSPC, % tempRateSPC
56
    Gui, Add, Text, x30 y65, Total click locations:
57
    Gui, Add, Edit, x133 y63 w50 Number Left vtotalClicks, % totalClicks
58
    Gui, Add, Text, x0 w210 0x10
59
    Gui, Add, Text, x27 y100, (Default is 50 clicks per second)
60
    Gui, Add, Button, x60 y117 gReset, Reset
61
    Gui, Add, Button, x112 y117 Default gSetVal, Set
62
    Gui, Font, s6
63
    Gui, Add, Text, x188 y151, v2.1.1
64
    if mode < 2
65
    {
66
      GuiControl,, Mode, 1
67
      GoSub, ActEdit1
68
    }
69
    else
70
    {
71
      GuiControl,, Seconds per click:, 1
72
      GoSub, ActEdit2
73
    }
74
  }
75
  else
76
    WinActivate, NIAC Settings
77
return
78
79
ActEdit1:
80
  GuiControl, Enable, tempRateCPS
81
  GuiControl, Disable, tempRateSPC
82
  GuiControl, Focus, tempRateCPS
83
  Send +{End}
84
return
85
86
ActEdit2:
87
  GuiControl, Enable, tempRateSPC
88
  GuiControl, Disable, tempRateCPS
89
  GuiControl, Focus, tempRateSPC
90
  Send +{End}
91
return
92
93
Reset:
94
  toggle := false
95
  actWin :=
96
  setTimer, autoClick, off
97
  currentClick := 1
98
  GuiControl, Disable, Reset
99
  Gui, Font, s8
100
  Gui, Add, Text, x54 y145, Click locations reset.
101
return
102
103
SetVal:
104
  Gui, Submit
105
  if mode < 2
106
    clickRate := tempRateCPS > 0 ? 1000 / tempRateCPS : 1000
107
  else
108
    clickRate := tempRateSPC > 0 ? 1000 * tempRateSPC : 1000
109
  if totalClicks != %prevTC%
110
  {
111
    toggle := false
112
    actWin :=
113
    setTimer, autoClick, off
114
  }
115
GuiClose:
116
  if toggle
117
  {
118
    EmptyMem()
119
    setTimer, autoclick, %clickRate%
120
  }
121
  Gui, Destroy
122
return
123
124
!Backspace::
125
  
126
  IfWinNotExist, NIAC Settings ; Only functional if options window is not open
127
  {
128
    toggle := !toggle
129
    if toggle
130
    {
131
      setTimer, setTip, 5
132
      if (!actWin) ; actWin value is also used to determine if checks are set. If they aren't:
133
      {
134
        settingPoints := true ; Used to allow break if options are opened
135
        Loop, %totalClicks%
136
        {
137
          if totalClicks < 2
138
            TooltipMsg = Click the desired autoclick location.
139
          else
140
            TooltipMsg = Click the location for point %A_Index%.
141
          toggle := false
142-
          Keywait, LButton, D
142+
          Keywait, RButton, D
143-
          Keywait, LButton
143+
          Keywait, RButton
144
          if !settingPoints ; Opening options sets this to false, breaking the loop
145
            return
146
          TooltipMsg = 
147
          newIndex := A_Index - 1
148
          MouseGetPos, xp%newIndex%, yp%newIndex%
149
          WinGet, actWin, ID, A
150
        }
151
        settingPoints := false
152
      }
153
      else ; If values ARE set (actWin contains data):
154
      {
155
        settingPoints := false
156
        setTimer, setTip, 5
157
        TTStart = %A_TickCount%
158
        TooltipMsg = ##Autoclick enabled.
159
      }
160
      toggle := true
161
      EmptyMem()
162
      setTimer, autoclick, %clickRate%
163
    }
164
    else
165
    {
166
       setTimer, setTip, 5
167
       TTStart = %A_TickCount%
168
       TooltipMsg = ##Autoclick disabled.
169
       setTimer, autoclick, off
170
    }
171
  }
172
return
173
174
setTip:
175
  StringReplace, cleanTTM, TooltipMsg, ##
176
  Tooltip, % cleanTTM
177
  if (InStr(TooltipMsg, "##") && A_TickCount - TTStart > 1000)
178
    TooltipMsg =
179
  if TooltipMsg =
180
  {
181
    Tooltip
182
    setTimer, setTip, off
183
  }
184
return
185
186
checkMouseMovement:
187
  if (WinExist("ahk_id" . actWin) || !actWin) ; If NIAC is clicking in a window, or the window isn't set, it's all good.
188
  {
189
    MouseGetPos, tx, ty
190
    if (tx == pmx && ty == pmy)
191
      mouseMoved := false
192
    else
193
      mouseMoved := true
194
    pmx := tx
195
    pmy := ty
196
  }
197
  else ; Otherwise, the target window has been closed.
198
  {
199
    Msgbox, 4, NIAC, Target window has been closed, `n Do you want to close NIAutoclicker as well?
200
    IfMsgBox Yes
201
      ExitApp
202
    else
203
    {
204
      actWin :=
205
      toggle := false
206
    }
207
  }
208
return
209
210
autoclick:
211
  if !(WinActive("ahk_id" . actWin) && (A_TimeIdlePhysical < 50 && !mouseMoved))
212
  {
213
    cx := xp%currentClick%
214
    cy := yp%currentClick%
215
    ControlClick, x%cx% y%cy%, ahk_id %actWin%,,,, NA
216
    currentClick := % Mod(currentClick + 1, totalClicks)
217
  }
218
return
219
220-
~*LButton up::
220+
~*RButton up::
221
return
222
223
#If WinActive("ahk_id" . actWin) && toggle
224-
$~*LButton::
224+
$~*RButton::
225
  MouseGetPos,,, winClick
226
  if winClick = %actWin%
227
    setTimer, autoclick, off
228-
  Send {Blind}{LButton Down}
228+
  Send {Blind}{RButton Down}
229
return
230
231-
$~*LButton up::
231+
$~*RButton up::
232
  IfWinNotExist, NIAC Settings
233
    setTimer, autoclick, %clickRate%
234-
  Send {Blind}{LButton Up}
234+
  Send {Blind}{RButton Up}
235
return
236
237
EmptyMem()
238
{
239
  pid:= DllCall("GetCurrentProcessId")
240
  h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)
241
  DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
242
  DllCall("CloseHandle", "Int", h)
243
}