How to add clipboard content to script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
feeko
Posts: 51
Joined: 15 Apr 2022, 00:20

How to add clipboard content to script?

28 Apr 2022, 16:45

I have a script right now that just sends a text. I want to add the content in my clipboard to this script so that it sends the clipboard + my text ("Test"). Is there a simple way to do that?

Code: Select all

^j::
Send, %A_Space%Test
return
I tried adding this just to see what it does and it did nothing. :lol:

Code: Select all

%ClipboardAll% %A_Space%Test
feeko
Posts: 51
Joined: 15 Apr 2022, 00:20

Re: How to add clipboard content to script?

28 Apr 2022, 18:16

Awesome thank you @AHKStudent. This is my new script.

Code: Select all

^j::
Send, % clipboard " Test"
return

How come the quotations are included when I don't put in the clipboard in the script and they aren't included when I put in the clipboard in the script?

Code: Select all

^j::
Send,  " Test"
return
Result = " Test"

Code: Select all

^j::
Send, % clipboard " Test"
return
Result = (clipboard) Test
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: How to add clipboard content to script?

28 Apr 2022, 18:19

Not the clipboard makes the difference, but the single % which forces an expression.
In expressions, strings need to be quoted, but the quotes are not part of the actual string. (In contrast, Send, " Test" isn't an expression.)

Code: Select all

Send, % " Test"
Result is _Test (well, not _, but a space in front)

In legacy (non-expression) syntax, you could use Send, %Clipboard%%A_Space%Test (not ClipboardAll).
feeko
Posts: 51
Joined: 15 Apr 2022, 00:20

Re: How to add clipboard content to script?

28 Apr 2022, 18:37

Thanks @gregster. Can you tell me about what you mean by legacy? And what's the big difference between those 2 scripts? Is one better than the other?

Code: Select all

^j::
Send, % clipboard " Test"
return

Code: Select all

^j::
Send, %Clipboard%%A_Space%Test
return
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: How to add clipboard content to script?

28 Apr 2022, 18:47

What I actually mean is non-expression syntax, which was traditionally and is still used in AHK commands. In contrast, expression syntax is eg used in the parameter list of functions. Some commands also accept expressions in their parameters (please check individual docs). But you can even force expressions (like seen above) for parameters of commands, which don't accept expressions by default. The Send command is one of those commands (msgbox is another one).

There is no big difference, they are equivalent. These are just different syntax variations (born out of backwards compatibility requirements in AHK v1, which started in 2003), but it is recommended to make yourself accustomed to expression syntax, because AHK v2 (now in beta development) exclusively uses it. This should finally end the confusion about two different, but parallel syntaxes.

I recommend to read the pages of the "Usage and Syntax" section of the docs, which explain these concepts in more depth (among many other useful things).
feeko
Posts: 51
Joined: 15 Apr 2022, 00:20

Re: How to add clipboard content to script?

28 Apr 2022, 19:32

Thanks for the explanation and links @gregster.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Draken, oktavimark and 371 guests