The issue you're experiencing is likely due to the fact that the Loop in AutoHotKey v2 is not designed to be used in the same way as in v1.1. In v2, the script is more sensitive to infinite loops and may terminate the script if it detects one.
To fix this issue, you can use a SetTimer instead of a Loop. Here's an updated version of the script:
; Auto Clicker Script
; Toggle variable to track the state of the auto clicker
autoClickerEnabled := false
; Hotkey to toggle the auto clicker
`::
{
; Toggle the auto clicker state
autoClickerEnabled := !autoClickerEnabled
; Display a tooltip to indicate the state change
if (autoClickerEnabled) {
ToolTip "Auto Clicker: ON"
} else {
ToolTip "Auto Clicker: OFF"
}
; Hide the tooltip after 1 second
SetTimer () => ToolTip(), -1000
}
; Timer to simulate mouse clicks
autoClickerTimer := ObjBindMethod({ClickFunc: (this) => Click()}, "ClickFunc")
SetTimer autoClickerTimer, 50 ; Adjust this value to change the click speed
; Function to simulate a left mouse button click
ClickFunc(this) {
if (autoClickerEnabled) {
Click
}
}
However, a more straightforward and idiomatic way to implement this in AutoHotKey v2 would be:
; Auto Clicker Script
; Toggle variable to track the state of the auto clicker
autoClickerEnabled := false
; Hotkey to toggle the auto clicker
`::
{
; Toggle the auto clicker state
autoClickerEnabled := !autoClickerEnabled
; Display a tooltip to indicate the state change
if (autoClickerEnabled) {
ToolTip "Auto Clicker: ON"
SetTimer ClickFunc, 50 ; Adjust this value to change the click speed
} else {
ToolTip "Auto Clicker: OFF"
SetTimer ClickFunc, 0
}
; Hide the tooltip after 1 second
SetTimer () => ToolTip(), -1000
}
; Function to simulate a left mouse button click
ClickFunc() {
Click
}
In this version, the SetTimer is started and stopped based on the state of the autoClickerEnabled variable. This is a more efficient and AutoHotKey v2-way of implementing an auto clicker.