OnClipboardChange

Registers a function to be called automatically whenever the clipboard's content changes.

OnClipboardChange Callback , AddRemove

Parameters

Callback

Type: Function Object

The function to call.

The callback accepts one parameter and can be defined as follows:

MyCallback(DataType) { ...

Although the name you give the parameter does not matter, it is assigned one of the following numbers:

You can omit the callback's parameter if the corresponding information is not needed, but in this case an asterisk must be specified, e.g. MyCallback(*).

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

AddRemove

Type: Integer

If omitted, it defaults to 1. Otherwise, specify one of the following numbers:

Remarks

If the clipboard changes while a callback 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, the callbacks are typically not executed immediately; that is, statements immediately below the statement that changed the clipboard are likely to execute beforehand. To force the callbacks 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(DataType) {
    ToolTip "Clipboard data type: " DataType
    Sleep 1000
    ToolTip  ; Turn off the tip.
}