OnClipboardChange

Causes the specified function to be called automatically whenever the clipboard's content changes.

OnClipboardChange Function , AddRemove

Parameters

Function

Type: Function Object

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

AddRemove

Type: Integer

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

Function

The function should accept one parameter:

FunctionName(Type)
Type

Type: Integer

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.

Remarks

If the clipboard changes while an OnClipboardChange function is already running, that notification event is lost. If this is undesirable, use Critical. 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, functions immediately below the function 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.

A_Clipboard, OnExit, OnMessage, CallbackCreate

Examples

Briefly displays a tooltip for each clipboard change.

OnClipboardChange ClipChanged

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