OnClipboardChange

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

OnClipboardChange Func , AddRemove

Parameters

Func

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

AddRemove

One of the following values:
1 (the default): Call the function after any previously registered functions.
-1: Call the function before any previously registered functions.
0: Do not call the function.

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

Func

FunctionName(Type)
Type

Contains one of the following values:
0 if the clipboard is now empty;
1 if it contains something that can be expressed as text (this includes files copied from an Explorer window);
2 if it contains something entirely non-text such as a picture.

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.

Example

The following example is a working script. Whenever it is running, it will briefly display a ToolTip for each clipboard change.

OnClipboardChange("ClipChanged")
return

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

Remarks

If the clipboard changes while an OnClipboardChange function 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 functions are typically not executed immediately; that is, commands immediately below the command that changed the clipboard are likely to execute beforehand. To force the functions to execute immediately, use a short delay such as Sleep 20 after changing the clipboard.

Related

Clipboard, OnExit, OnMessage, RegisterCallback