Pause - Syntax & Usage | AutoHotkey

AutoHotkey

Pause

Pauses the script's current thread.

#p::Pause ; Pressing Win+P once will pause the script. Pressing it again will unpause.
Pause , On|Off|Toggle, OperateOnUnderlyingThread?

Parameters

On|Off|Toggle

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

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

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.

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

Specify one of the following numbers:

0 (or omitted): 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).

Note: A_IsPaused contains 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 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 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 the Menu 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.)

Related

Suspend, Menu, ExitApp, Threads, SetTimer

Examples

Pause::Pause  ; Assign the toggle-pause function to the "pause" key...
#p::Pause  ; ... or assign it to Win+p or some other hotkey.
; Send a Pause command to another script.
DetectHiddenWindows, On
WM_COMMAND := 0x111
ID_FILE_PAUSE := 65403
PostMessage, WM_COMMAND, ID_FILE_PAUSE,,, C:\YourScript.ahk ahk_class AutoHotkey