Function cannot return ClipboardAll

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scoox
Posts: 118
Joined: 11 May 2014, 09:12
Location: China

Function cannot return ClipboardAll

21 Feb 2019, 09:34

[Moderator's note: Topic moved from Bug Reports.]

Hi, just bumped into the following problem:

Code: Select all

!v::
	Clipboard := ;Clear clipboard
	Clipboard := MyFunc() ;MyFunc() returns "hello world", write this string to clipboard
	SendInput, ^v ;Paste clipboard contents (should paste "hello world")
Return

MyFunc()
{
	Clipboard := "hello world" ;Put "hello world" in Clipboard
	MyVar := ClipboardAll ;Write Clipboard to MyVar. MyVar now contains "hello world"
	Return MyVar ;Return MyVar i.e. function returns "hello world"
}
The return value of MyFunc() is the contents of ClipboardAll, which is assigned back to Clipboard. This results in an empty clipboard. Could this be a bug? Thanks
Last edited by Scoox on 21 Feb 2019, 21:59, edited 1 time in total.
iPhilip
Posts: 413
Joined: 02 Oct 2013, 12:21

Re: Function cannot return ClipboardAll

21 Feb 2019, 11:52

As posted, it works for me, i.e. !v and ^v return hello world.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
Scoox
Posts: 118
Joined: 11 May 2014, 09:12
Location: China

Re: Function cannot return ClipboardAll

21 Feb 2019, 22:01

iPhilip wrote:
21 Feb 2019, 11:52
As posted, it works for me, i.e. !v and ^v return hello world.
Dang! It was supposed to be MyVar := ClipboardAll, my bad. Please try again, thanks!
iPhilip
Posts: 413
Joined: 02 Oct 2013, 12:21

Re: Function cannot return ClipboardAll

22 Feb 2019, 00:00

Hi Scoox,

The documentation says:
https://autohotkey.com/docs/misc/Clipboard.htm#ClipboardAll wrote: Binary-clipboard variables may be passed to functions by value (formerly they only worked ByRef).
It doesn't say that clipboard variables can be returned by a function. This works in place of what you posted:

Code: Select all

!v::
   Clipboard := ;Clear clipboard
   MyFunc(Var) ;MyFunc() returns "hello world" in Var
   Clipboard := Var ;Write this string to clipboard
   SendInput, ^v ;Paste clipboard contents (should paste "hello world")
   Var := ;Free the variable in case the clipboard was very large
Return

MyFunc(ByRef MyVar) {
   Clipboard := "hello world" ;Put "hello world" in Clipboard
   MyVar := ClipboardAll ;Write Clipboard to MyVar. MyVar now contains "hello world"
}
I hope it helps.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
Helgef
Posts: 3924
Joined: 17 Jul 2016, 01:02
Contact:

Re: Function cannot return ClipboardAll

22 Feb 2019, 02:43

Your code is perfectly logic and it is reasonable to believe it should work, however, ClipboardAll is one of the quirks of v1, You should take this part of the documentation literally, it is complete,
A variable containing clipboard data can be copied to another variable as in this example: ClipSaved2 := ClipSaved.

This issue is fixed in v2 :thumbup: .

Cheers.
User avatar
Scoox
Posts: 118
Joined: 11 May 2014, 09:12
Location: China

Re: Function cannot return ClipboardAll

23 Feb 2019, 21:05

iPhilip wrote:
22 Feb 2019, 00:00
It doesn't say that clipboard variables can be returned by a function.
... though it doesn't say clipboard variables cannot be returned either (at least I didn't find it). From your replies here this looks like a quirk + documentation issue.
User avatar
nnnik
Posts: 4251
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Function cannot return ClipboardAll

24 Feb 2019, 05:30

Well yeah assigning ClipboardAll ro another variable and writing it to a file using FileAppend is all you can do with it.
Having ClipboardAll and Clipboard as a variable in the first place was a mistake imo.
Recommends AHK Studio
User avatar
Scoox
Posts: 118
Joined: 11 May 2014, 09:12
Location: China

Re: Function cannot return ClipboardAll

24 Feb 2019, 20:35

nnnik wrote:
24 Feb 2019, 05:30
Well yeah assigning ClipboardAll ro another variable and writing it to a file using FileAppend is all you can do with it.
Having ClipboardAll and Clipboard as a variable in the first place was a mistake imo.
Yeah, I would have preferred two functions, something like ClipboardGet(Mode:=0) and ClipboardPut(Mode:=0), where Mode tells the function whether to deal with raw clipboard data (0) or just text (1). And maybe even a ClipboardSwap(Data, Mode:=0).
iPhilip
Posts: 413
Joined: 02 Oct 2013, 12:21

Re: Function cannot return ClipboardAll

27 Feb 2019, 20:53

Hi Scoox,

I have this post by lexikos bookmarked to remind me of the v1 limitations around binary variables.

Cheers!

- iPhilip
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Ortorin and 230 guests