Elegant solution to send multi-line text line by line? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
sh00ter666
Posts: 18
Joined: 07 Oct 2016, 10:55

Elegant solution to send multi-line text line by line?

Post by sh00ter666 » 12 Jul 2017, 04:45

Greetings,

I would like to accomplish an easy to maintain source for inserting and swapping out multi-line texts that are being sent line by line. In essence I bet it is quite easy to realize, though I cannot quite come up with anything efficient and elegant.

The core idea is to send song lyrics line by line in a chat.

I do it this way right now:

Code: Select all

$F8::
SendInput Maybe I'm foolish, maybe I'm blind
Send {Enter}
Sleep 3350

SendInput Thinking I can see through this and see what's behind 
Send {Enter}
Sleep 3350

SendInput Got no way to prove it so maybe I'm blind
Send {Enter}
Sleep 4350

; etc. . .

return

Obviously swapping out 5-10 lines like this takes ages and requires back and forth switching, copy pasting, etc.


I would love for something like this in theory:

Code: Select all

lyrics=
(
this
is a multiline
text passage

with some paragraphs
and spaces
does this even work?
)

; ---
;function call
sendLyrics(lyrics)

I firmly believe that some of you smart people can easily come up with something fitting :dance:

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Elegant solution to send multi-line text line by line?

Post by Helgef » 12 Jul 2017, 04:54

Sendinput % lyrics :thumbup:
Edit:
With sleeps and paragraphs:

Code: Select all

sendLyrics(lyrics){
	Loop, Parse, lyrics, `n, `r
	{
		if (A_LoopField=""){
			Send,{Enter}
			continue
		}
		Send, % A_LoopField  "`n" 
		Sleep, 3500
	}
}
Last edited by Helgef on 12 Jul 2017, 05:01, edited 1 time in total.

Rohwedder
Posts: 7768
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Elegant solution to send multi-line text line by line?  Topic is solved

Post by Rohwedder » 12 Jul 2017, 04:58

Hallo,
with Sleeps:

Code: Select all

lyrics=
(
this
is a multiline
text passage

with some paragraphs
and spaces
does this even work?
)
sendLyrics(lyrics)

Return
sendLyrics(lyrics)
{
	Loop, Parse, lyrics, `n
	{
		SendInput, % A_LoopField  
		Send {Enter}
		Sleep 3350
	}
}


User avatar
sh00ter666
Posts: 18
Joined: 07 Oct 2016, 10:55

Re: Elegant solution to send multi-line text line by line?

Post by sh00ter666 » 15 Jul 2017, 06:39

Thank you guys, as always you two are of immensurable help!! :bravo: :dance:

The snippet is looking very good, unfortunately it's not working in either of the two applications I tested it within.

This is what I have:

Code: Select all

$F8::
sendLyrics(song)
return

song=
(
this
is a 
test	
)

sendLyrics(lyrics){
	Loop, Parse, lyrics, `n, `r
	{
		if (A_LoopField=""){
			Send,{Enter}
			continue
		}
		Send, % A_LoopField  "`n" 
		Sleep, 2111
	}
}

One of the applications was a chat that would not require an extra keypress to open a chatbox, so this should be working, but unfortunately it doesn't.

The second attempt was within a DirectX game that would require an extra held down {Enter} Input, to open the chatbox first before every line of text.

I would have went with something like the following within the function loop before every line of text.

Code: Select all

SetKeyDelay, 55, 50
 SendEvent, {Enter}

Edit Hold up, I just tested it within Notepad, and not even then it's working :salute: I must be doing something wrong :mrgreen:

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Elegant solution to send multi-line text line by line?

Post by Helgef » 15 Jul 2017, 07:04

Hi. See auto execute section in the help file. Example, compare,

Code: Select all

; End auto execute section
a::
	Msgbox, % var
return
var:="Hello world"
vs

Code: Select all

var:="Hello world"
; End auto execute section
a::
	Msgbox, % var
return
Cheers.

User avatar
sh00ter666
Posts: 18
Joined: 07 Oct 2016, 10:55

Re: Elegant solution to send multi-line text line by line?

Post by sh00ter666 » 15 Jul 2017, 07:45

Yeah, I think I know what you're saying and it is something that I had tried prior to posting.

But even those two examples you linked above, yield the same result for me. In both instances, an empty Message Box. This should be happening, right?


Does the snippet that you have provided in post#2 work for yourself @Helgef?

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Elegant solution to send multi-line text line by line?

Post by Helgef » 15 Jul 2017, 08:28

Code box #1 should show empty an msgbox, code box #2 should show Hello world, and so it does on my computer.
The first code I posted (post number two in this thread) worked on my computer as well.

User avatar
sh00ter666
Posts: 18
Joined: 07 Oct 2016, 10:55

Re: Elegant solution to send multi-line text line by line?

Post by sh00ter666 » 15 Jul 2017, 10:06

What the actual hell? I have tested this so many times now. . .

What could possibly be wrong with my machine?

Image URL



Nvm, works now. Apparently the lazy bit of reload code caused trouble because no line breaks? This means that it doesn't work in my main script, because something before the snippet interferes :evil:

Image


Alright, marked as solved again, since it works with a fresh attempt :monkeysee: :monkeysee: :monkeysay:

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Elegant solution to send multi-line text line by line?

Post by Helgef » 15 Jul 2017, 10:49

esc::reload ends the auto execute section, hence, var:="..." will not be exectued.

TheJoe570
Posts: 1
Joined: 05 Jan 2024, 09:39
Contact:

Re: Elegant solution to send multi-line text line by line?

Post by TheJoe570 » 05 Jan 2024, 09:41

Thanks for taking the time to share the code. exactly what I was looking for.

Post Reply

Return to “Ask for Help (v1)”