How to Send text as one string?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
slishnevsky
Posts: 34
Joined: 07 Mar 2024, 06:50

How to Send text as one string?

11 May 2024, 19:10

Hello.

I was playing with the Send command.
It seems it can only send text character by character, like typing.
I was wondering if it is possible to send a text as a whole string?

Thanks.
User avatar
kunkel321
Posts: 1136
Joined: 30 Nov 2015, 21:19

Re: How to Send text as one string?

12 May 2024, 09:23

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+

^+p:: ; Ctrl+Shift+P, save to clipboard, then simulate paste.
{
	A_Clipboard := "I was playing with the Send command.`nIt seems it can only send text character by character, like typing.`nI was wondering if it is possible to send a text as a whole string?`n`nI was playing with the Send command.`nIt seems it can only send text character by character, like typing.`nI was wondering if it is possible to send a text as a whole string?`n`nI was playing with the Send command.`nIt seems it can only send text character by character, like typing.`nI was wondering if it is possible to send a text as a whole string?`n`nI was playing with the Send command.`nIt seems it can only send text character by character, like typing.`nI was wondering if it is possible to send a text as a whole string?`n`nI was playing with the Send command.`nIt seems it can only send text character by character, like typing.`nI was wondering if it is possible to send a text as a whole string?"
	Send "^{v}" ; Ctrl+V tells Windows to paste content of clipboard.  
}
ste(phen|ve) kunkel
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: How to Send text as one string?

12 May 2024, 10:15

I would use ClipWait.

Code: Select all

#Requires AutoHotkey v2.0
str := 'I was playing with the Send command.`nIt seems it can only send text character by character,'
     . ' like typing.`nI was wondering if it is possible to send a text as a whole string?`n`n'
str .= str str str

^+p::paste(str)

paste(str) {
 A_Clipboard := ''
 A_Clipboard := str
 If ClipWait(1)
  Send '^v'
 Else MsgBox 'An error occurred while waiting for the clipboard.', 'Error', 'Icon!'
}
User avatar
kunkel321
Posts: 1136
Joined: 30 Nov 2015, 21:19

Re: How to Send text as one string?

12 May 2024, 10:30

mikeyww wrote:
12 May 2024, 10:15
I would use ClipWait.
Yeah, good call.

I guess it's also worth mentioning that if you are pasting multiple paragraphs, you can have the variable assignment with a multiline continuation section.
This takes more lines of code, but it is easier to understand.

Code: Select all

	A_Clipboard := "
	(
	I was playing with the Send command.
	It seems it can only send text character by character, like typing.
	I was wondering if it is possible to send a text as a whole string?

	I was playing with the Send command.
	It seems it can only send text character by character, like typing.
	I was wondering if it is possible to send a text as a whole string?

	I was playing with the Send command.
	It seems it can only send text character by character, like typing.
	I was wondering if it is possible to send a text as a whole string?

	I was playing with the Send command.
	It seems it can only send text charater by character, like typing.
	I was wondering if it is possible to send a text as a whole string?

	I was playing with the Send command.
	It seems it can only send text character by character, like typing.
	I was wondering if it is possible to send a text as a whole string?
	)"
ste(phen|ve) kunkel
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: How to Send text as one string?

12 May 2024, 13:30

That is what I thought for a while, but I had an instance where I thought that the ClipWait made a difference. I might have been mistaken and defer to lexikos's expertise. If I encounter the problem again, I will post.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww, RussF and 30 guests