Pause

Pauses the script's current thread.

Pause NewState

Parameters

NewState

Type: Integer

If 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

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.

The tray icon changes to a green icon with a Pause symbol (or to a green icon with a transparent Pause symbol if the script is also suspended), whenever the script's current thread is in a paused state. This icon change can be avoided by freezing the icon, which is achieved by using TraySetIcon(,, true).

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.)

The built-in variable A_IsPaused contains 1 if the thread immediately underneath the current thread is paused and 0 otherwise.

Suspend, Menu object, ExitApp, Threads, SetTimer

Examples

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.

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

Sends a Pause command to another script.

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