Pause

Pauses the script's current thread.

Pause NewState

Parameters

NewState

Type: Integer or String

If blank or omitted, the current thread is paused. Otherwise, specify one of the following values:

1 or True: Marks the thread beneath the current thread as paused so that when it resumes, it will finish the function it was running (if any) and then enter a paused state. If there is no thread beneath the current thread, the script itself is paused, which prevents timers from running (this effect is the same as having used the menu item "Pause Script" while the script has no threads).

0 or False: Unpauses the underlying thread.

-1: Toggles the pause state of the underlying thread.

Remarks

A_IsPaused contains the pause state of the underlying thread.

By default, the script can also be paused via its tray icon or main window.

Unlike Suspend -- which disables hotkeys and hotstrings -- turning on pause will freeze the thread (the current thread if NewState was omitted, otherwise the underlying thread). As a side-effect, any interrupted threads beneath it will lie dormant.

Whenever any thread is paused, timers will not run. By contrast, explicitly launched threads such as hotkeys and menu items can still be launched; but when their threads finish, the underlying thread will still be paused. In other words, each thread can be paused independently of the others.

With the default icons, the color of the tray icon changes from green to red whenever the script's current thread is in a paused state. This color change can be avoided by freezing the icon, which is achieved by specifying 1 for the last parameter of TraySetIcon. For example:

TraySetIcon ,, 1

To disable timers without pausing the script, use Thread "NoTimers".

A script is always halted (though not officially paused) while it is displaying any kind of menu (tray menu, menu bar, GUI context menu, etc.)

Related

Suspend, Menu object, ExitApp, Threads, SetTimer

Examples

#1: Use Pause to halt the script, such as to inspect variables.

ListVars
Pause
ExitApp ; This line will not execute until the user unpauses the script.

#2: Press a hotkey once to pause the script. Press it again to unpause.

Pause::Pause -1  ; The Pause/Break key.
#p::Pause -1  ; Win+P

#3: Send a Pause command to another script.

DetectHiddenWindows True
WM_COMMAND := 0x111
ID_FILE_PAUSE := 65403
PostMessage WM_COMMAND, ID_FILE_PAUSE,,, "C:\YourScript.ahk ahk_class AutoHotkey"