OnClipboardChange() [v1.1.20+]

Registers a function or function object to run whenever the clipboard's content changes.

OnClipboardChange(Func , AddRemove)



A function name or function object to call. The function's parameter and return value are described below.


If blank or omitted, it defaults to 1 (call the function after any previously registered functions). Otherwise, specify one of the following numbers:

If an OnClipboardChange label exists, it is always called first.



Contains one of the following numbers:

Return Value

If this is the last or only OnClipboardChange function, the return value is ignored. Otherwise, the function can return a non-zero integer to prevent subsequent functions from being called.

OnClipboardChange Label

Deprecated: This approach is not recommended for use in new scripts. Use the OnClipboardChange function instead.

A label named OnClipboardChange (if it exists) is launched automatically whenever any application (even the script itself) has changed the contents of the clipboard. The label also runs once when the script first starts.

The built-in variable A_EventInfo contains one of the following numbers:


If the clipboard changes while an OnClipboardChange function or label is already running, that notification event is lost. If this is undesirable, specify Critical as the label's first line. However, this will also buffer/defer other threads (such as the press of a hotkey) that occur while the OnClipboardChange thread is running.

If the script itself changes the clipboard, its OnClipboardChange function or label is typically not executed immediately; that is, commands immediately below the command that changed the clipboard are likely to execute beforehand. To force the function or label to execute immediately, use a short delay such as Sleep 20 after changing the clipboard.

Clipboard, OnExit(), OnExit, OnMessage(), RegisterCallback()


Function vs. Label.

Despite the different approach, both examples have the same effect; that is, they briefly display a tooltip for each clipboard change. Note that the function is not called when the script first starts; only when the contents of the clipboard changes.


ClipChanged(Type) {
    ToolTip Clipboard data type: %Type%
    Sleep 1000
    ToolTip  ; Turn off the tip.

ToolTip Clipboard data type: %A_EventInfo%
Sleep 1000
ToolTip  ; Turn off the tip.