Page 1 of 1

Issues with OnClipboardChange

Posted: 05 Apr 2020, 05:12
by gemisigo
I have some issues with OnClipboardChange.

Registering a function with

Code: Select all

OnClipboardChange("MyFunction", 1)
works. But when I try to "disable" the registered function with

Code: Select all

OnClipboardChange("MyFunction", 0)
that call of OnClipboardChange runs without any reported errors, yet MyFunction is still executed on each clipboard change.

Any hints on why that might happen?

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 05:24
by BNOLI
Is it the same if you use the sample code from AHK's help with the additional AddRemove-parameter, just out of curiosity?

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 05:37
by gemisigo
If you're referring to something like this

Code: Select all

#Persistent
OnClipboardChange("ClipChanged")
Return 

^+F11::
    OnClipboardChange("ClipChanged", 0)
Return

^+F12::
    OnClipboardChange("ClipChanged", 1)
return

return

ClipChanged(Type) {
    ToolTip Clipboard data type: %Type%
    Sleep 1000
    ToolTip  ; Turn off the tip.
}
then yes, that one seems to be working. The code, where it does not, is much more complicated than that. It has two functions for handling changes on the clipboard, and two functions that should be able to turn those other to on and off:

Code: Select all


saved_on_clipboard(_type) {
	; some arbitrary content
}

count_on_clipboard(_type, _color = "FFFFAA", _action = "copy", _timeout = 7)  {
	; again, some arbitrary content
}

register_clip_change_functions() {
    OnClipboardChange("saved_on_clipboard", 1)
    OnClipboardChange("count_on_clipboard", 1)
}

unregister_clip_change_functions() {
    OnClipboardChange("saved_on_clipboard", 0)
    OnClipboardChange("count_on_clipboard", 0)
}
Turning them by calling register_clip_change_functions on works. Turning them off by calling unregister_clip_change_functions does not.

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 10:36
by haichen
that was nonsens what i posted

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 10:53
by teadrinker
For me, this code works correctly:

Code: Select all

saved_on_clipboard(_type) {
   MsgBox, % A_ThisFunc
}

count_on_clipboard(_type, _color = "FFFFAA", _action = "copy", _timeout = 7)  {
   MsgBox, % A_ThisFunc
}

$F1::
register_clip_change_functions() {
    OnClipboardChange("saved_on_clipboard", 1)
    OnClipboardChange("count_on_clipboard", 1)
}
$F2::
unregister_clip_change_functions() {
    OnClipboardChange("saved_on_clipboard", 0)
    OnClipboardChange("count_on_clipboard", 0)
}
You could enable both functions by pressing F1 and disable them by pressing F2.

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 11:07
by haichen
Also working:

Code: Select all

F11:: register_clip_change_functions(1) ;register
F12:: register_clip_change_functions(0) ;unregister
return 

saved_on_clipboard(type) {
   MsgBox, % A_ThisFunc
}

count_on_clipboard(type)  {
    MsgBox, % A_ThisFunc
}

register_clip_change_functions(Type) {
    OnClipboardChange("saved_on_clipboard", Type)
    OnClipboardChange("count_on_clipboard", Type)
    tooltip % type
}
edit: works without ByRef, so i changed that

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 16:58
by gemisigo
These simple examples work here too.
Is there anything that could prevent OnClipboardChange to disable the requested functions? Or at least a way to check which ones are still active?

Re: Issues with OnClipboardChange

Posted: 05 Apr 2020, 19:07
by swagfag
there might be, who knows. do u have an example of broken code u can share that demonstrates the problem? otherwise, there is nothing to troubleshoot. everything posted so far works.
also what ahk version?