Page 1 of 1

Clipboard

Posted: 28 May 2018, 11:23
by Flipeador
Hello!
I would like to propose a change regarding the current behavior of AHK with the clipboard. Apparently, when you set text to the clipboard, it is first emptied, so any other format is completely lost... Is this the behavior we want?; I mean, if you copy a file and then change the clipboard text (CF_UNICODETEXT), then the CF_HDROP data is lost (related).
I know, specifying an empty string Clipboard:="" is useful for using with ClipWait, but... You lose all other formats!.
Would not it be better to have a separate method/function to empty the clipboard? (ClipboardEmpty or Clipboard:=ClipboardAll(0) or Clipboard NewText [, Empty?]).

Maybe I missed something, if that is the case, please let me know.
:wave:

Re: Clipboard

Posted: 28 May 2018, 15:13
by nnnik
Yes this is the behaviour you want.
Clipboard replaces the current content of the clipboard with another one. A single content may be available in multiple formats. Making the replacement of content the default beahviour makes the most sense.
If you want advanced clipboard functionality I reccomend the DllCall functions ( although you probably know them already. )

Re: Clipboard

Posted: 28 May 2018, 15:49
by Flipeador
I propose this because the use of the clipboard is quite common and there are many scripts that make use of it. I do not think that this is something advanced, it seems to me something very basic and useful.
A single content may be available in multiple formats
But, this does not make sense. If you are going to establish plain text on the clipboard, the ideal is using the CF_UNICODETEXT format, so all applications can use it. In addition, AutoHotkey only recognizes 3 formats: CF_TEXT, CF_UNICODETEXT and CF_HDROP.

Why delete all other formats If you are only going to establish text?.

Re: Clipboard

Posted: 28 May 2018, 16:33
by Flipeador
A new ClipboardEmpty function would be fine and convert the Clipboard variable to a function.
Clipboard [StrOrAddr] [, SizeAddr] [, Format]
If StrOrAddr is omited, get te content in the specified format (default text). If the specified format is not text (CF_TEXT or CF_UNICODETEXT), you can return a memory address and SizeAddr the size of the content.
If SrrOrAddr is 0, delete the specified format.
In any other case, it establishes the content in the specified format.
Although I recognize that this could be considered "advanced".

Re: Clipboard  Topic is solved

Posted: 28 May 2018, 17:40
by Flipeador
Well, I've been thinking it better and maybe the current behavior is the most appropriate, although I have not been able to do tests because I'm not at home.
I have thought that if an application creates its own format to store text, it will give priority to that format and CF_UNICODETEXTcould be ignored. So emptying the clipboard is the best. Even so, the function that I proposed in my previous comment could be very useful to register our own format and store text in a line of code Clipboard("Text",, "some format name").

Re: Clipboard

Posted: 28 May 2018, 23:47
by nnnik
Well the most basic reason why a simple solution wouldn't work with your idea is bugs.
Imagine if word set the clipboards normal text format and it's own special formatted text format.
Now we only overwrite the normal text but keep the formatted text.
When we now press Ctrl+V in Word we won't get the content we stored into the clipboard but rather the data that was inside before because Word will prefer the special format.

Re: Clipboard

Posted: 29 May 2018, 00:24
by Flipeador
Yes, I said that in my previous comment, and I thought exactly in Word as well. :)

Re: Clipboard

Posted: 29 May 2018, 04:50
by just me

Re: Clipboard

Posted: 01 Jun 2018, 21:26
by lexikos
If you assign a := b, would you expect a to now contain b and other, previously-stored data?

Assignment semantics require that Clipboard := x replaces the current clipboard content.

Re: Clipboardaf

Posted: 14 Jul 2018, 13:23
by aenigma14344
Flipeador wrote:Well, I've been thinking it better and maybe the current behavior is the most appropriate, although I have not been able to do tests because I'm not at home.
I have thought that if an application creates its own format to store text, it will give priority to that format and CF_UNICODETEXTcould be ignored. So emptying the clipboard is the best. Even so, the function that I proposed in my previous comment could be very useful to register our own format and store text in a line of code Clipboard("Text",, "some format name").