Explain the AddRemove parameter in OnClipboardChange? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Explain the AddRemove parameter in OnClipboardChange?

11 Nov 2021, 01:29

Problem:
Explain the AddRemove parameter in OnClipboardChange?

What does it mean by Call the function after any previously registered functions?
What are previously registered functions?

Quote:
https://www.autohotkey.com/docs/commands/OnClipboardChange.htm wrote:
OnClipboardChange(Func , AddRemove)

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

1 = Call the function after any previously registered functions.
-1 = Call the function before any previously registered functions.
User avatar
boiler
Posts: 17392
Joined: 21 Dec 2014, 02:44

Re: Explain the AddRemove parameter in OnClipboardChange?  Topic is solved

11 Nov 2021, 02:00

NorInd wrote: What are previously registered functions?
It means a function you had already set up to be called using OnClipboardChange(). Example:

Code: Select all

#Persistent
OnClipboardChange("FnA")
OnClipboardChange("FnB", -1)
return

FnA() {
	MsgBox, Function A
}

FnB() {
	MsgBox, Function B
}
Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: Explain the AddRemove parameter in OnClipboardChange?

11 Nov 2021, 08:26

boiler wrote:
11 Nov 2021, 02:00
It means a function you had already set up to be called using OnClipboardChange(). Example:
I'm sorry to disturb here but I will like to learn a bit more. Are you sure that it means "a function you already set up"

I mean, Helps talk about "-1 = Call the function before any previously registered functions. ", but keep in mind that many other programs on Windows OS can register themselves on OnClipboardChange().
Windows OS maintain a list (array of callbacks) from those programs that want to be nofified on clipboards changes.

I think that a "-1" means that your program will be notified before any other program that is registered on "Windows OS". In this way you can create a "clipboard viewer/manager" that always be the first to be notified. In facts most clipboards manager do this, it changes again the content of the clipboard and the rest of programs already registered won't see the first change of the clipboard (there are techniques to do that,if you return a non zero value on your callback function, that changes won't be sent to the others registered windows, if you return zero, it will be, to be honest I don't know how it works on AHK, that's why I ask).
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.
Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: Explain the AddRemove parameter in OnClipboardChange?

11 Nov 2021, 10:16

-------------deleted, so nobody get wrong with the old text--------------
Last edited by Lepes on 11 Nov 2021, 12:54, edited 1 time in total.
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Explain the AddRemove parameter in OnClipboardChange?

11 Nov 2021, 11:15

@Lepes,
previously registered functions
are functions previously registered by the currently running AHK script to run whenever the clipboard's content changes, i.e. you can register various functions.
Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: Explain the AddRemove parameter in OnClipboardChange?

11 Nov 2021, 12:22

just me wrote:
11 Nov 2021, 11:15
@Lepes,
previously registered functions
are functions previously registered by the currently running AHK script to run whenever the clipboard's content changes, i.e. you can register various functions.
So we can not create a clipboard manager in AHK. Imaging this Scenario:
Clipboard callbacks: [ program1, AHK, program2]

We copy a text "Hello world", program1 don't touch the text and return 0, so AHK receives the text and changes to "I'm AHK" and return 0:
program1 receives "Hello world"
AHK receives "Hello world"
program2 receives "I'm AHK"
At this point I mess up the clipboard.

If we were capable of inserting on first place of the clipboard callbacks, all programs will receive "I'm AHK" that it is what is spected from a Clipboard Manager.

Don't get me wrong, I don't doubt about what you are saying, I already said that I'm a newbie on AHK, but I did a clipboard Manager con Delphi 7 with Windows Api and that's the way Windows Clipboard works. So helpfile lacks this appreciation? I mean it is not about other Clipboard registered applications?
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Explain the AddRemove parameter in OnClipboardChange?

12 Nov 2021, 09:07

@Lepes, AHK is calling AddClipboardFormatListener() on Win Vista+. OnClipboardChange() defines the internal functions to be called whenever AHK receives a WM_CLIPBOARDUPDATE notification.
Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: Explain the AddRemove parameter in OnClipboardChange?

12 Nov 2021, 11:50

Thank you @boiler and @just me

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Galvanise, Google [Bot], rakizi, Rohwedder and 171 guests