</head> <body> <h1>#Persistent</h1> <p>Keeps a script permanently running (that is, until the user closes it or <a href="ExitApp.htm">ExitApp</a> is encountered).</p> <pre class="Syntax"><span class="func">#Persistent</span></pre> <p>A script is persistent if any of the following conditions are true:</p> <ul> <li>At least one <a href="../Hotkeys.htm">hotkey</a> or <a href="../Hotstrings.htm">hotstring</a> has been defined in the script or created by the <a href="Hotkey.htm">Hotkey</a> command or <a href="Hotstring.htm">Hotstring</a> function, even if it is not enabled.</li> <li>The <a href="_InstallKeybdHook.htm">keyboard hook</a> or <a href="_InstallMouseHook.htm">mouse hook</a> is installed.</li> <li>The script contains any use of <a href="Gui.htm">Gui</a>, even if it has not been called.</li> <li>The script contains any use of <a href="OnMessage.htm">OnMessage</a>, or has called it dynamically or retrieved a reference with <a href="Func.htm">Func</a>.</li> <li>The <a href="Input.htm">Input</a> command has been called.</li> <li>The #Persistent directive is present anywhere in the script.</li> </ul> <p>Use this directive to prevent the script from exiting after the <a href="../Scripts.htm#auto">auto-execute section</a> (top part of the script) completes. This is useful in cases where a script contains <a href="SetTimer.htm">timers</a> and/or <a href="Menu.htm">custom menu items</a> but does not meet any of the other conditions listed above.</p> <p>If this directive is added to an existing script, you might want to change some or all occurrences of <a href="Exit.htm">Exit</a> to be <a href="ExitApp.htm">ExitApp</a>. This is because <a href="Exit.htm">Exit</a> will not terminate a persistent script; it terminates only the <a href="../misc/Threads.htm">current thread</a>.</p> <p><span class="ver">[v1.0.16+]</span>: This directive also makes a script single-instance. To override this or change the way single-instance behaves, see <a href="_SingleInstance.htm">#SingleInstance</a>.</p> <p>Like other directives, #Persistent cannot be executed conditionally.</p> <h2 id="Related">Related</h2> <p><a href="_SingleInstance.htm">#SingleInstance</a>, <a href="SetTimer.htm">SetTimer</a>, <a href="Menu.htm">Menu</a>, <a href="Exit.htm">Exit</a>, <a href="ExitApp.htm">ExitApp</a></p> <h2 id="Examples">Examples</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> Causes the script to run permanently; that is, it will not exit automatically if it could.</p> <pre>#Persistent</pre> </div> </body> </html>