There are at least two approaches. The first is to make a new hotkey that pauses the entire script. For example, this makes Ctrl-Alt-p do that:
^!p::pause ; toggle the pause state off and on
The other approach is to use a variable to make your #x hotkey multi-purpose, so that pressing it again will turn off the looping activity. Here's how to do it:
Code:
; Allow multiple threads so that this hotkey can "turn itself off":
#MaxThreadsPerHotkey 2
#x::
#MaxThreadsPerHotkey 1
if keep_x_running = y
{
keep_x_running = n ; Signal the other thread to stop.
return
}
keep_x_running = y
Loop 100,
{
if keep_x_running = n ; Another thread signaled us to stop
return
LeftClick, 530, 378
Sleep, 100
Send, Text
Sleep, 100
LeftClick, 472, 415
Sleep, 100
LeftClick, 520, 552
Sleep, 100
LeftClick, 470, 580
Sleep, 100
}
In the above, you can repeat the following section more often (e.g. after every sleep) if you need the stopping to be more instantaneous:
if keep_x_running = n
return