Skip to content

Instantly share code, notes, and snippets.

@ericchase
Created March 1, 2024 23:35
Show Gist options
  • Save ericchase/6d03568ea9abc7d1f5af8545fd146bd8 to your computer and use it in GitHub Desktop.
Save ericchase/6d03568ea9abc7d1f5af8545fd146bd8 to your computer and use it in GitHub Desktop.

Revisions

  1. ericchase created this gist Mar 1, 2024.
    64 changes: 64 additions & 0 deletions autoclick
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    #Requires AutoHotkey >=2.0 <2.1

    #SingleInstance Force
    #UseHook true

    DetectHiddenWindows true
    FileEncoding "UTF-8"
    SendMode "Event" ; Event mode intersperses delays between actions. Needed for games.
    SetTitleMatchMode 3 ; A window's title must exactly match WinTitle to be a match.
    Thread "Interrupt", 15 ; Sets the priority or interruptibility of threads.

    ; This code restarts the script in admin mode if needed.
    g_CommandLine := DllCall("GetCommandLine", "str")

    if not A_IsAdmin or not RegExMatch(g_CommandLine, " /restart(?!\S)") {
    try {
    if A_IsCompiled {
    Run('*RunAs "' A_ScriptFullPath '" /restart')
    }
    else {
    Run('*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"')
    }
    }
    ExitApp
    }

    g_X := 0
    g_Y := 0

    g_Toggle_Click := false
    fn_RepeatClick() {
    global
    if (g_Toggle_Click = true) {
    MouseClick("Left", g_X, g_Y, 1, 0, "D")
    Sleep(50)
    MouseClick("Left", , , , 0, "U")
    Send("x")
    SetTimer(fn_RepeatClick, -250)
    } else {
    Send("{y up}")
    SetTimer(fn_RepeatClick, 0)
    }
    }
    fn_ToggleRepeatClick() {
    global
    g_Toggle_Click := !g_Toggle_Click
    SetTimer(fn_RepeatClick, 0)
    if (g_Toggle_Click = true) {
    MouseGetPos(&g_X, &g_Y)
    Send("{y down}")
    Sleep(1000)
    fn_RepeatClick()
    } else {
    Send("y")
    }
    }

    *XButton2:: fn_ToggleRepeatClick

    ~Escape:: {
    global
    g_Toggle_Click := false
    Send("y")
    }