How to stop a script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bxgchoi
Posts: 16
Joined: 28 Oct 2020, 13:48

How to stop a script

28 Oct 2020, 19:00

Hi Everyone,

Is there a way to immediately stop and end my script from continuing further?

For example, this is my script:

Code: Select all

^5::
MouseMove, 2948, 312
MouseClick, Right
Sleep, 2000
MouseMove, 55, 92, 0, R
MouseClick, Left
MouseMove -1600, 200, 0, R
MouseClick, Left
return
How can i make it so that if i press {ESC} it automatically stops and ends the script if it's only halfway or so through? Thank you in advance!
Last edited by SKAN on 28 Oct 2020, 19:06, edited 1 time in total.
Reason: Added [code] tags
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: How to stop a script  Topic is solved

28 Oct 2020, 19:05

Add Esc::ExitApp to your script
Greast
Posts: 71
Joined: 24 Oct 2020, 19:01

Re: How to stop a script

28 Oct 2020, 19:41

You can use a suspend AutoHotkey function, just press [ESC] and the script stop working, press again and it works.

Code: Select all

Esc::
Suspend, Off
Pause, Off, 1
If (toggle := !toggle) {
 Suspend, On
 Pause, On, 1
}
Rohwedder
Posts: 7768
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to stop a script

29 Oct 2020, 06:59

Hallo,
the same shortened:

Code: Select all

Esc::
Suspend
Pause,, 1
Return
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to stop a script

29 Oct 2020, 07:46

Excellent! Thank you for sharing that.
bxgchoi
Posts: 16
Joined: 28 Oct 2020, 13:48

Re: How to stop a script

29 Oct 2020, 10:00

SKAN wrote:
28 Oct 2020, 19:05
Add Esc::ExitApp to you script
Where do i add this? The end or beginning? Thank you in advance!
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to stop a script

29 Oct 2020, 10:11

Generally speaking, a hotkey (or hotstring or subroutine) can exist anywhere in the script below the top auto-execute section. So just put it somewhere, and the script will find it when you press that hotkey.
bxgchoi
Posts: 16
Joined: 28 Oct 2020, 13:48

Re: How to stop a script

29 Oct 2020, 11:19

mikeyww wrote:
29 Oct 2020, 10:11
Generally speaking, a hotkey (or hotstring or subroutine) can exist anywhere in the script below the top auto-execute section. So just put it somewhere, and the script will find it when you press that hotkey.
Thank you!
mikeahk
Posts: 24
Joined: 04 Nov 2017, 14:24

Re: How to stop a script

18 Nov 2020, 07:40

I am using the following script that I got from mikeyww in another post to stop a script. I’ve got a great e number of keys remapped to do various things, and those keys include critical letters that are easily within reach (eg qwer) but occasionally I have to do some actual flat out typing. So I’m using this script to exit the script so that I can use qwer keys.

Code: Select all

F7::
Suspend, Off
Pause, Off, 1
If (toggle := !toggle) 
 Suspend, On
 Pause, On, 1
Return
and it works just fine, but what I would like to do is merely pause ( not exit ) the script by hitting F7… do some normal typing … then reengage the script by hitting F7 again. Or, to keep things simple, press F8 or some other key to reengage the script.

Any idea how to do this? As always greatly appreciated.
mikeahk
Posts: 24
Joined: 04 Nov 2017, 14:24

Re: How to stop a script

18 Nov 2020, 07:44

Wait I just realized that the script does pause the function – rather than exiting. I can unsuspend the script with a couple of mouse clicks. Still I would love to hit F7 or F8 to reengage the function
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to stop a script

18 Nov 2020, 07:49

Code: Select all

F7::Suspend, Toggle
Any hotkey/hotstring subroutine whose very first line is Suspend (except Suspend On) will be exempt from suspension. In other words, the hotkey will remain enabled even while suspension is ON. This allows suspension to be turned off via such a hotkey.
mikeahk
Posts: 24
Joined: 04 Nov 2017, 14:24

Re: How to stop a script

18 Nov 2020, 09:50

Suspends and un suspends like a charm

PJ Whoopee – You're the greatest!
blackdog1
Posts: 1
Joined: 22 May 2024, 10:51

Re: How to stop a script

22 May 2024, 10:58

mikeyww wrote:
29 Oct 2020, 07:46
Excellent! Thank you for sharing that.
Great script worked perfectly, thank you

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: balawi28, Chunjee, moltenchees and 263 guests