Pause

Pauses the script's current thread.

Pause , OnOffToggle, OperateOnUnderlyingThread

Parameters

OnOffToggle

If blank or omitted, it defaults to Toggle. Otherwise, specify one of the following words:

On: Pauses the current thread.

Off: If the thread beneath the current thread is paused, it will be in an unpaused state when resumed. Otherwise, the command has no effect.

Toggle: Pauses the current thread unless the thread beneath it is paused, in which case the underlying thread is unpaused.

[v1.1.30+]: The decimal values 1, 0 and -1 may be used in place of On, Off and Toggle, respectively.

OperateOnUnderlyingThread

This parameter is ignored for Pause Off because that always operates on the underlying thread. For the others, it is ignored unless Pause is being turned on (including via Toggle).

If blank or omitted, it defaults to 0. Otherwise, specify one of the following numbers:

0: The command pauses the current thread; that is, the one now running the Pause command.

1: The command marks the thread beneath the current thread as paused so that when it resumes, it will finish the command 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).

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 current 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 red H icon (or to a red S icon 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 specifying 1 for the Freeze parameter of the Menu's Icon sub-command. For example:

Menu, Tray, Icon, C:\My Icon.ico, , 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.)

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

Suspend, Menu, ExitApp, Threads, SetTimer

Examples

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

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

Sends a Pause command to another script.

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