Skip to content

Instantly share code, notes, and snippets.

@arcaartem
Created May 26, 2024 23:26
Show Gist options
  • Save arcaartem/3f1a6733b5af13e182f4fa06196fefb0 to your computer and use it in GitHub Desktop.
Save arcaartem/3f1a6733b5af13e182f4fa06196fefb0 to your computer and use it in GitHub Desktop.
AutoHotKey v2 Script That Moves The Mouse Randomly
toggle := true ; Start with the script enabled
timer := 5000
SetTimer(MoveMouse, timer) ; Set the timer to trigger every "timer" seconds
Return
^+#m:: ; Ctrl+Shift+Win M hotkey
{
global toggle
toggle := !toggle
if toggle {
SetTimer(MoveMouse, timer) ; Re-enable the timer
MsgBox "Mouse moving script enabled"
} else {
SetTimer(MoveMouse, 0) ; Disable the timer
MsgBox "Mouse moving script disabled"
}
}
MoveMouse() {
global toggle
if toggle {
screenWidth := A_ScreenWidth
screenHeight := A_ScreenHeight
randX := Random(0, screenWidth)
randY := Random(0, screenHeight)
MouseGetPos(&currentX, &currentY)
distanceX := randX - currentX
distanceY := randY - currentY
steps := 100
Loop steps {
progress := A_Index / steps
easeProgress := EaseInOutCubic(progress)
stepX := distanceX * easeProgress - distanceX * EaseInOutCubic((A_Index - 1) / steps)
stepY := distanceY * easeProgress - distanceY * EaseInOutCubic((A_Index - 1) / steps)
MouseMove(stepX, stepY, 0, "R")
Sleep(10)
}
}
}
EaseInOutCubic(t) {
if t < 0.5
return 4 * t * t * t
else {
t := 2 * t - 2
return 0.5 * t * t * t + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment