is exit a safe command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Shekhar Singh
Posts: 115
Joined: 06 Dec 2022, 02:35

is exit a safe command

Post by Shekhar Singh » 24 Jan 2023, 00:47

hi , in documentation for exit command it is specifically written that the command does not work well . it exit current thread or sometimes whole script , does that mean the script runs in background while using exit command .

Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: is exit a safe command

Post by Rohwedder » 24 Jan 2023, 01:53

Hallo,
if you think the command Exit does not work well, then you have not understood the documentation well.
Even if Exit is not explicitly in the script, every Autohotkey v1.1 script contains this command. Try to run this

Code: Select all

Switch
and you will see it in the error window.

User avatar
DevWithCoffee
Posts: 54
Joined: 13 Oct 2020, 12:16

Re: is exit a safe command

Post by DevWithCoffee » 24 Jan 2023, 13:11

The exit command is for finishing the Script itself, probably you want to close a GUI, but in that case you should use:
https://www.autohotkey.com/docs/v2/lib/Gui.htm#Destroy

Now if you are running routines you need to learn how to use Loop:
https://www.autohotkey.com/docs/v2/lib/Loop.htm#ExBreakContinue

Something I highly recommend:
https://www.autohotkey.com/docs/v2/Concepts.htm#boolean

One thing I recommend is always using some means to analyze the variables in your scripts in real time, remembering to remove them later. I use this one to keep the Debug window from getting in the way of testing operations:
https://www.autohotkey.com/docs/v2/lib/ToolTip.htm

Example:

Code: Select all

... Public Variables ...
Loop
{
	... My Script ...
	Tooltip % "Var 1: " myvar "`nVar 2:" myvar2
	If (condition to break...)
	{
		break
	}
	Sleep 10
}
ExitApp

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: is exit a safe command

Post by iseahound » 24 Jan 2023, 13:55

The exit command ends the current thread.

If you use a hotkey

Code: Select all

h:: Exit
pressing H will launch a new thread and end the new thread

but if you put Exit in the main thread,

Code: Select all

MsgBox
Exit
it will exit the main thread, and because the main thread is the script, it will exit the script itself.

However, if you say the main thread can never be exited,

Code: Select all

#persistent
MsgBox
Exit
Then Exit does nothing (I think).

Shekhar Singh
Posts: 115
Joined: 06 Dec 2022, 02:35

Re: is exit a safe command

Post by Shekhar Singh » 28 Jan 2023, 02:12

Hi , @icehound
if used as hotkey than will it exit the current script.

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: is exit a safe command

Post by iseahound » 30 Jan 2023, 11:37

It's working fine for me on v2
image.png
image.png (43.83 KiB) Viewed 199 times
and v1
image.png
image.png (44.78 KiB) Viewed 199 times

Post Reply

Return to “Ask for Help (v1)”