Skip to content

Instantly share code, notes, and snippets.

@tdolan21
Last active October 2, 2025 00:24
Show Gist options
  • Save tdolan21/bf5bdcc4ff8431539cb2c7181fcf7938 to your computer and use it in GitHub Desktop.
Save tdolan21/bf5bdcc4ff8431539cb2c7181fcf7938 to your computer and use it in GitHub Desktop.
AutoHotKey v2 Anti-AFK tool with unique mouse movement pattern and small transparent overlay
; Requires AutoHotkey v2.0
; Download the gist and double click to run
; Enhanced Anti-AFK Script with Window Controls & Styling
; This script prevents AFK detection by performing mouse movements
; Press Ctrl+Alt+S to start/stop the anti-AFK feature
; Press Ctrl+Alt+X to exit the script completely
; Global variables
afkPrevention := false
moveInterval := 180000 ; Default: Move every 3 minutes (180000 milliseconds)
moveDistance := 10 ; Default movement distance
statusGui := 0 ; Will hold our status window
countdownSeconds := 0 ; For countdown display
movementPatterns := ["circle", "square", "zigzag"] ; Different movement patterns
currentPattern := 1 ; Index of the current pattern
; Create a status window with controls and styling
CreateStatusWindow() {
global statusGui
; Create the GUI with standard window controls
statusGui := Gui("+AlwaysOnTop +MinSize320x240")
statusGui.Title := "Anti-AFK Controller"
statusGui.MarginX := 15
statusGui.MarginY := 15
statusGui.BackColor := "333333" ; Dark background
statusGui.SetFont("s10 c00FF00", "Segoe UI") ; Green text
; Add a header
header := statusGui.Add("Text", "y5 w300 Center", "Anti-AFK Control Panel")
header.SetFont("s12 bold cFFFFFF") ; White text for header
; Add a divider
statusGui.Add("Text", "xs y+10 w300 0x10") ; Horizontal line
; Add status indicator with better spacing
statusGui.Add("Text", "xs y+15 w80", "Status:")
statusGui.Add("Text", "x+10 w150 vStatusText", "INACTIVE")
; Add timer text
statusGui.Add("Text", "xs y+15 w80", "Next move:")
statusGui.Add("Text", "x+10 w150 vCountdownText", "--:--")
; Add pattern selector
statusGui.Add("Text", "xs y+15 w80", "Pattern:")
patternDropdown := statusGui.Add("DropDownList", "x+10 w150 vPatternDropdown Choose1", movementPatterns)
patternDropdown.OnEvent("Change", OnPatternChange)
; Add interval control
statusGui.Add("Text", "xs y+15 w80", "Interval (s):")
intervalEdit := statusGui.Add("Edit", "x+10 w70 vIntervalEdit Number", moveInterval / 1000)
statusGui.Add("UpDown", "Range30-3600", moveInterval / 1000)
statusGui.Add("Button", "x+10 w70 vApplyBtn", "Apply")
; Add a divider
statusGui.Add("Text", "xs y+15 w300 0x10") ; Horizontal line
; Add control buttons with better spacing
statusGui.Add("Button", "xs y+15 w130 vStartStopBtn", "Start (Ctrl+Alt+S)")
statusGui.Add("Button", "x+20 w130 vExitBtn", "Exit (Ctrl+Alt+X)")
; Set up button events
statusGui["StartStopBtn"].OnEvent("Click", ToggleAFK)
statusGui["ExitBtn"].OnEvent("Click", ExitScript)
statusGui["ApplyBtn"].OnEvent("Click", ApplySettings)
; Position in the top-right corner of the primary monitor
MonitorGetWorkArea(1, &monLeft, &monTop, &monRight, &monBottom)
windowWidth := 310
windowHeight := 270
xPos := monRight - windowWidth - 20
yPos := monTop + 50
statusGui.Show(Format("x{} y{} w{} h{}", xPos, yPos, windowWidth, windowHeight))
; Set transparency for the green styled look
WinSetTransparent(230, "ahk_id " . statusGui.Hwnd)
return statusGui
}
; Toggle the anti-AFK feature
ToggleAFK(*) {
global afkPrevention, statusGui
if (afkPrevention) {
; Turn off the timer
SetTimer(MoveMouseSlightly, 0)
SetTimer(UpdateCountdown, 0)
afkPrevention := false
UpdateStatusDisplay(false)
statusGui["StartStopBtn"].Text := "Start (Ctrl+Alt+S)"
} else {
; Turn on the timer
SetTimer(MoveMouseSlightly, moveInterval)
SetTimer(UpdateCountdown, 1000)
afkPrevention := true
UpdateStatusDisplay(true)
statusGui["StartStopBtn"].Text := "Stop (Ctrl+Alt+S)"
}
}
; Handle pattern change
OnPatternChange(ctrl, *) {
global currentPattern
currentPattern := ctrl.Value
}
; Apply interval settings
ApplySettings(*) {
global moveInterval, afkPrevention, statusGui
newInterval := statusGui["IntervalEdit"].Value
if (newInterval && newInterval >= 30 && newInterval <= 3600) {
moveInterval := newInterval * 1000
if (afkPrevention) {
SetTimer(MoveMouseSlightly, 0) ; Clear old timer
SetTimer(MoveMouseSlightly, moveInterval) ; Set new timer
countdownSeconds := moveInterval / 1000 ; Reset countdown
UpdateStatusDisplay(true)
}
SoundPlay "*-1" ; Play a sound to confirm settings applied
ToolTip("Settings applied - Interval: " . newInterval . " seconds", 10, 10)
SetTimer(() => ToolTip(), -2000) ; Hide the tooltip after 2 seconds
}
}
; Exit the script
ExitScript(*) {
if (statusGui) {
statusGui.Destroy()
}
ExitApp()
}
; Update the status display
UpdateStatusDisplay(isActive := false) {
global statusGui, countdownSeconds, moveInterval
if (!statusGui) {
return
}
if (isActive) {
statusGui["StatusText"].Value := "ACTIVE"
statusGui["StatusText"].Opt("c00FF00") ; Green text
countdownSeconds := moveInterval / 1000
statusGui["CountdownText"].Value := FormatTime(countdownSeconds)
statusGui.Title := "Anti-AFK Controller [ACTIVE]"
} else {
statusGui["StatusText"].Value := "INACTIVE"
statusGui["StatusText"].Opt("cFF6600") ; Orange text
statusGui["CountdownText"].Value := "--:--"
statusGui.Title := "Anti-AFK Controller"
}
}
; Format time as MM:SS
FormatTime(seconds) {
minutes := Floor(seconds / 60)
remainingSeconds := Mod(seconds, 60)
return Format("{:02}:{:02}", minutes, remainingSeconds)
}
; Update the countdown timer display
UpdateCountdown() {
global statusGui, countdownSeconds
countdownSeconds -= 1
if (countdownSeconds < 0) {
countdownSeconds := moveInterval / 1000
}
statusGui["CountdownText"].Value := FormatTime(countdownSeconds)
}
; Perform a circular mouse movement
CircleMovement(centerX, centerY, radius) {
steps := 16
angleStep := 360 / steps
Loop steps {
angle := A_Index * angleStep * (3.14159 / 180) ; Convert to radians
newX := centerX + radius * Cos(angle)
newY := centerY + radius * Sin(angle)
MouseMove(Round(newX), Round(newY), 2) ; Smoother movement with speed 2
Sleep(25)
}
; Return to center
MouseMove(centerX, centerY, 2)
}
; Perform a square mouse movement
SquareMovement(centerX, centerY, size) {
halfSize := size / 2
startX := centerX - halfSize
startY := centerY - halfSize
; Move to start position
MouseMove(startX, startY, 2)
Sleep(50)
; Top edge
MouseMove(startX + size, startY, 2)
Sleep(50)
; Right edge
MouseMove(startX + size, startY + size, 2)
Sleep(50)
; Bottom edge
MouseMove(startX, startY + size, 2)
Sleep(50)
; Left edge back to start
MouseMove(startX, startY, 2)
Sleep(50)
; Return to center
MouseMove(centerX, centerY, 2)
}
; Perform a zigzag mouse movement
ZigzagMovement(centerX, centerY, size) {
halfSize := size / 2
startX := centerX - halfSize
startY := centerY - halfSize
steps := 4
stepSize := size / steps
currentX := startX
currentY := startY
Loop steps {
; Move down and right
currentX += stepSize
currentY += stepSize
MouseMove(currentX, currentY, 2)
Sleep(50)
; Move up and right (if not at end)
if (A_Index < steps) {
currentX += stepSize
currentY -= stepSize
MouseMove(currentX, currentY, 2)
Sleep(50)
}
}
; Return to center
MouseMove(centerX, centerY, 2)
}
; Create the timer function that will move the mouse
MoveMouseSlightly() {
global statusGui, currentPattern, moveDistance
; Flash the status indicator
statusGui["StatusText"].Opt("cFFFF00") ; Yellow text
statusGui["StatusText"].Value := "MOVING"
; Store current mouse position
MouseGetPos(&centerX, &centerY)
; Choose movement pattern based on selection
switch movementPatterns[currentPattern] {
case "circle":
CircleMovement(centerX, centerY, moveDistance * 2)
case "square":
SquareMovement(centerX, centerY, moveDistance * 3)
case "zigzag":
ZigzagMovement(centerX, centerY, moveDistance * 3)
}
; Reset status indicator
Sleep(500)
statusGui["StatusText"].Opt("c00FF00") ; Green text
statusGui["StatusText"].Value := "ACTIVE"
; Reset countdown
countdownSeconds := moveInterval / 1000
}
; Hotkey to toggle the anti-AFK feature
^!s::ToggleAFK()
; Hotkey to exit the script
^!x::ExitScript()
; Create a tray menu for configuration
tray := A_TrayMenu
tray.Add("Show/Hide Window", ToggleStatusWindow)
tray.Add() ; Add a separator
tray.Add("Exit", (*) => ExitApp())
; Function to toggle the status window
ToggleStatusWindow(*) {
global statusGui
if (statusGui) {
if (WinExist("ahk_id " . statusGui.Hwnd)) {
statusGui.Hide()
} else {
statusGui.Show()
}
} else {
statusGui := CreateStatusWindow()
UpdateStatusDisplay(afkPrevention)
}
}
; Create the status window on startup
statusGui := CreateStatusWindow()
; Initialize script with a notification
SoundPlay "*64" ; Play a system sound to indicate script has started
ToolTip("Anti-AFK Script Started", 10, 10)
SetTimer(() => ToolTip(), -3000) ; Hide the tooltip after 3 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment