AutoHotKey Key Interrupt Cycle

Using AutoHotKey, I have a pretty simple script loop that I want to break down by key stroke. I tried several different codes from websites, but it doesn't seem to work.

Here is the code:

#g:: Loop 20 { MouseClick, left, 142, 542 Sleep, 1000 MouseClick, left, 138, 567 Sleep, 1500 MouseClick, left, 97, 538 Sleep, 1000 } 
+6
source share
4 answers

Use a global variable (keepCycling) and switch it to break the loop. Global variables must be declared at the beginning of the script.

+2
source

Adding a global variable may be the easiest solution for your case, as your loop takes some time.

 global break_g = 0 #b:: break_g = 1 return #g:: break_g = 0 Loop 20 { MouseClick, left, 142, 542 Sleep, 1000 MouseClick, left, 138, 567 Sleep, 1500 MouseClick, left, 97, 538 Sleep, 1000 if( break_g = 1) { return } } return ; also you were missing this return 
+1
source
 #g:: Loop 20 { KeyWait,Ctrl,D T0 if Errorlevel = 0 break MouseClick, left, 142, 542 KeyWait,Ctrl,D T0 if Errorlevel = 0 break Sleep, 1000 KeyWait,Ctrl,D T0 if Errorlevel = 0 break MouseClick, left, 138, 567 KeyWait,Ctrl,D T0 if Errorlevel = 0 break Sleep, 1500 KeyWait,Ctrl,D T0 if Errorlevel = 0 break MouseClick, left, 97, 538 KeyWait,Ctrl,D T0 if Errorlevel = 0 break Sleep, 1000 } return 

Using the above can be useful since the effect will be instantaneous. Most often, you stop your loop when you hold Ctrl on an interval.

0
source

Switching a global variable is the way to go. You need to declare it at the beginning of the script.

global keep_working = 1; set the gap at the beginning of the script

b ::; set break keep_working = 0 return

g ::; set the job and run the keep_working = 1 loop
Loop ;; loop until b is pressed (there was a loop, 20 in the source code) {MouseClick, left, 142, 542 Sleep, 1000 MouseClick, left, 138, 567 Sleep, 1500 MouseClick, left, 97, 538 Sleep, 1000 if (keep_working = 0) {return; need to stop execution}} return; this separator is required at the end of the hotkey procedure.

0
source

Source: https://habr.com/ru/post/943582/


All Articles