Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

AutoHotkey Auto Clicker

Go to solution Solved by PorkishPig,

Here's some things that went wrong:

  • Calling the macro inside a loop, you can't do this.
  • Setting BreakLoop to 1 immediately after beginning the loop, causing if (BreakLoop = 1) to test positive and break the loop.

You're looking for something like this:

#SingleInstance Force
#MaxThreadsPerHotkey 3

clickDelay := 5

ESC::
	Toggle := !Toggle
	While (Toggle) {
		MouseClick, Left
		Sleep clickDelay
	}
	Return

Explanation:

  • Each time ESC is pressed, the script will switch Toggle to the opposite of its current value.
    Therefore, Toggle is switching between 1 when running and 0 when not running. The while loop will execute while Toggle = 1.
  • clickDelay is the amount of time in ms between loops.
  • #MaxThreadsPerHotkey ensures you can run the hotkey again during active execution.

 

So I wrote a script in AutoHotkey that should click infinitely unless Esc is pressed but it doesn't seem to work. Can you spot the mistake?

 

My script:

 

Spoiler

BreakLoop = 0;
Loop,
{
Esc::
BreakLoop = 1;
if (BreakLoop = 1)
  break 
MouseClick, left
}

 

 

Link to post
Share on other sites

Here's some things that went wrong:

  • Calling the macro inside a loop, you can't do this.
  • Setting BreakLoop to 1 immediately after beginning the loop, causing if (BreakLoop = 1) to test positive and break the loop.

You're looking for something like this:

#SingleInstance Force
#MaxThreadsPerHotkey 3

clickDelay := 5

ESC::
	Toggle := !Toggle
	While (Toggle) {
		MouseClick, Left
		Sleep clickDelay
	}
	Return

Explanation:

  • Each time ESC is pressed, the script will switch Toggle to the opposite of its current value.
    Therefore, Toggle is switching between 1 when running and 0 when not running. The while loop will execute while Toggle = 1.
  • clickDelay is the amount of time in ms between loops.
  • #MaxThreadsPerHotkey ensures you can run the hotkey again during active execution.

 

Make sure to quote me or use @PorkishPig to notify me that you replied!

 

 

Desktop

CPU - Ryzen 9 3900X | Cooler - Noctua NH-D15 | Motherboard - ASUS TUF X570-PLUS RAM - Corsair Vengeance LPX DDR4-3200 16GB (2x8) Case - Meshify C

GPU - RTX 3080 FE PSU - Straight Power 11 850W Platinum Storage - 960 EVO 500GB, S31 1TB, MX500 500GB | OS - Windows 10 Pro

 

Homelab

CPU - Core i5-11400 | Cooler - Noctua NH-U12S | Motherboard - ASRock Z590M-ITX RAM - G.Skill Ripjaws V DDR4-3600 32GB (2x16)  | Case - Node 304

PSU - EVGA B3 650W | Storage - 860 EVO 256GB, Sabrent Rocket 4.0 1TB, WD Red 4TB (x6 in RAIDZ1 w/ LSI 9207-8i) | OS - TrueNAS Scale (Debian)

Link to post
Share on other sites
21 hours ago, PorkishPig said:

Here's some things that went wrong:

  • Calling the macro inside a loop, you can't do this.
  • Setting BreakLoop to 1 immediately after beginning the loop, causing if (BreakLoop = 1) to test positive and break the loop.

You're looking for something like this:


#SingleInstance Force
#MaxThreadsPerHotkey 3

clickDelay := 5

ESC::
	Toggle := !Toggle
	While (Toggle) {
		MouseClick, Left
		Sleep clickDelay
	}
	Return

Explanation:

  • Each time ESC is pressed, the script will switch Toggle to the opposite of its current value.
    Therefore, Toggle is switching between 1 when running and 0 when not running. The while loop will execute while Toggle = 1.
  • clickDelay is the amount of time in ms between loops.
  • #MaxThreadsPerHotkey ensures you can run the hotkey again during active execution.

 

 Btw it is not sleeping but I don't want it to anyways.

Link to post
Share on other sites
1 hour ago, Wictorian said:

 Btw it is not sleeping but I don't want it to anyways.

clickDelay is in milliseconds, you'll need to use a value higher than 100 to see a significant difference.

Make sure to quote me or use @PorkishPig to notify me that you replied!

 

 

Desktop

CPU - Ryzen 9 3900X | Cooler - Noctua NH-D15 | Motherboard - ASUS TUF X570-PLUS RAM - Corsair Vengeance LPX DDR4-3200 16GB (2x8) Case - Meshify C

GPU - RTX 3080 FE PSU - Straight Power 11 850W Platinum Storage - 960 EVO 500GB, S31 1TB, MX500 500GB | OS - Windows 10 Pro

 

Homelab

CPU - Core i5-11400 | Cooler - Noctua NH-U12S | Motherboard - ASRock Z590M-ITX RAM - G.Skill Ripjaws V DDR4-3600 32GB (2x16)  | Case - Node 304

PSU - EVGA B3 650W | Storage - 860 EVO 256GB, Sabrent Rocket 4.0 1TB, WD Red 4TB (x6 in RAIDZ1 w/ LSI 9207-8i) | OS - TrueNAS Scale (Debian)

Link to post
Share on other sites
1 hour ago, PorkishPig said:

clickDelay is in milliseconds, you'll need to use a value higher than 100 to see a significant difference.

Oh ok, thanks. 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×