Issues with OnClipboardChange

Get help with using AutoHotkey and its commands and hotkeys
gemisigo
Posts: 9
Joined: 08 Jul 2014, 03:29

Issues with OnClipboardChange

05 Apr 2020, 05:12

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?
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: Issues with OnClipboardChange

05 Apr 2020, 05:24

Is it the same if you use the sample code from AHK's help with the additional AddRemove-parameter, just out of curiosity?
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
gemisigo
Posts: 9
Joined: 08 Jul 2014, 03:29

Re: Issues with OnClipboardChange

05 Apr 2020, 05:37

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.
User avatar
haichen
Posts: 485
Joined: 09 Feb 2014, 08:24

Re: Issues with OnClipboardChange

05 Apr 2020, 10:36

that was nonsens what i posted
teadrinker
Posts: 1735
Joined: 29 Mar 2015, 09:41
Contact:

Re: Issues with OnClipboardChange

05 Apr 2020, 10:53

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.
User avatar
haichen
Posts: 485
Joined: 09 Feb 2014, 08:24

Re: Issues with OnClipboardChange

05 Apr 2020, 11:07

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
gemisigo
Posts: 9
Joined: 08 Jul 2014, 03:29

Re: Issues with OnClipboardChange

05 Apr 2020, 16:58

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?
swagfag
Posts: 3900
Joined: 11 Jan 2017, 17:59

Re: Issues with OnClipboardChange

05 Apr 2020, 19:07

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?

Return to “Ask For Help”

Who is online

Users browsing this forum: 4k3or3et, AHKStudent, boiler, nacken012, rhaos and 43 guests