I put this script together from searching through the forums and the documentation.
I just wanted to ask what I can do to clean up my coding in AHK.
The "doesn't work reliably" comment near the bottom refers to the toggling off after activating the loop.
Code: Select all
; Delays "x"ms with added randomness
randDelay(x)
{
Random, rand, 0, 4000
rand := Sqrt(rand)*10
rand := round(rand)
sleep x + rand
}
; Presses key with random press time (avg. time 130ms)
randKey(x)
{
Random, rand, 0, 40000
rand := Round(Sqrt(%rand%)/10)
SendInput {%x% down}
Random, plus, 0, 1
if (plus = 0)
{
rand := -%rand%
}
Sleep 130 + rand
SendInput {%x% up}
}
; Presses mouse button (copy pasted code) with random press time (avge. time 110ms)
randClick()
{
Random, rand, 0, 40000
rand := Round(Sqrt(%rand%)/10)
Send {LButton down}
Random, plus, 0, 1
if (plus = 0)
{
rand := -%rand%
}
Sleep 110 + rand
SendInput {LButton up}
}
; Main Program
#MaxThreadsPerHotkey 2
; Looped code toggles with pressed keybind Alt+\ (doesn't work reliably for whatever reason)
!\::
{
Toggle:=!Toggle
While, Toggle
{
randClick()
randDelay(1500)
randKey(1)
randDelay(23500)
}
}