How can I paste text containing linebreaks Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

How can I paste text containing linebreaks

28 Aug 2020, 05:42

Dear all,
I am trying to use my paste function to paste the variable called init.

This variable contains multiple lines of text which I want to separate using line breaks.

Reading up the documentation I am supposed to use `n, however its not working still pasting as one block without spaces.

Is my paste function interfering with the linebreaks?

Code: Select all

ControlClick, WindowsForms10.Window.8.app.0.2eed1ca_r9_ad150
init := 1. text for line 1 bla bla bla bla `n
          2. text for line 2 bla bla bla bla `n
          3. text for line 3 bla bla bla bla `n
          4. text for line 4 bla bla bla bla `n
          5. text for line 5 bla bla bla bla `n	
	paste(init) 
		
return

Paste(text) {
	Clipboard := text
	Send, {Control down}v{Control up}
	sleep, 500
}

Appreciate your help
James
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How can I paste text containing linebreaks

28 Aug 2020, 06:01

Code: Select all

ControlClick, WindowsForms10.Window.8.app.0.2eed1ca_r9_ad150
init = 
(LTrim
          1. text for line 1 bla bla bla bla
          2. text for line 2 bla bla bla bla
          3. text for line 3 bla bla bla bla
          4. text for line 4 bla bla bla bla
          5. text for line 5 bla bla bla bla
)	
paste(init) 
return

Paste(text) {
          clipboard := text
          Send, {Control down}v{Control up}
          }
Keyword: 'continuation section'
RubbeH
Posts: 49
Joined: 13 Jul 2020, 08:40

Re: How can I paste text containing linebreaks

28 Aug 2020, 06:02

This works for me

Code: Select all

F5::
{
init :="
(
1. text for line 1 bla bla bla bla
2. text for line 2 bla bla bla bla
3. text for line 3 bla bla bla bla
4. text for line 4 bla bla bla bla
5. text for line 5 bla bla bla bla
)"
paste(init) 
}
return
Paste(text) {
	Clipboard := text
	Send, {Control down}v{Control up}
	sleep, 500
}
Otherwise to use the `n

Code: Select all

init := "1. text for line 1 bla bla bla bla`n2. text for line 2 bla bla bla bla`n3. text for line 3 bla bla bla bla`n4. text for line 4 bla bla bla bla`n5. text for line 5 bla bla bla bla"
Edit: Perhaps you would like to restore clipboard after pasting, In that case you can change your function to this:

Code: Select all

Paste(text) {
	ClipSave := ClipboardAll
	Clipboard := text
	Send, {Control down}v{Control up}
	Clipboard := ClipSave
	sleep, 500
}
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: How can I paste text containing linebreaks

31 Aug 2020, 16:56

Thanks for your help.
@BoBo I tried your script but unfortunately it pasted without any separation or linebreaks; just one block of text

@RubbeH I tried both your f5 and `n script. For the `n script I tested as below on notepad. with either script there was no separation of each line (see below attached pic of result on notepad.)

When you tested this on notepad what did the text look like and was each line separated?
Thanks

Code: Select all

#UseHook On


SetKeyDelay, -1 
SetTitleMatchMode, 2

^!3::
init := "1. text for line 1 bla bla bla bla`n2. text for line 2 bla bla bla bla`n3. text for line 3 bla bla bla bla`n4. text for line 4 bla bla bla bla`n5. text for line 5 bla bla bla bla"
paste(init) 
Esc::ExitApp  ; Exit script with Escape key

return

Paste(text) {
	Clipboard := text
	Send, {Control down}v{Control up}
	sleep, 500
}

f5 no line break.PNG
f5 no line break.PNG (18.11 KiB) Viewed 663 times
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How can I paste text containing linebreaks

31 Aug 2020, 17:01

So, you've enabled Notepad's Format > Line Break-option already?? :wtf:
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: How can I paste text containing linebreaks

31 Aug 2020, 17:16

Try:

Code: Select all

^!3::
init := "1. text for line 1 bla bla bla bla`r`n2. text for line 2 bla bla bla bla`r`n3. text for line 3 bla bla bla bla`r`n4. text for line 4 bla bla bla bla`r`n5. text for line 5 bla bla bla bla"
paste(init) 
return

Esc::ExitApp  ; Exit script with Escape key

Paste(text) {
	ClipSave := ClipboardAll
	Clipboard := text
	Send, ^v ;{Control down}v{Control up}
	sleep, 500
	Clipboard := ClipSave
}
Edit: Restoring Clipboard correctley
RubbeH
Posts: 49
Joined: 13 Jul 2020, 08:40

Re: How can I paste text containing linebreaks

01 Sep 2020, 00:32

JKnight_xbt33 wrote:
31 Aug 2020, 16:56
When you tested this on notepad what did the text look like and was each line separated?
Thanks

Code: Select all

#UseHook On


SetKeyDelay, -1 
SetTitleMatchMode, 2

^!3::
init := "1. text for line 1 bla bla bla bla`n2. text for line 2 bla bla bla bla`n3. text for line 3 bla bla bla bla`n4. text for line 4 bla bla bla bla`n5. text for line 5 bla bla bla bla"
paste(init) 
;Add a return here, otherwise your script will exit immediately after execution as it will continue to the hotkey below it.
Esc::ExitApp  ; Exit script with Escape key
return ; you can remove this return.

Paste(text) {
	Clipboard := text
	Send, {Control down}v{Control up}
	sleep, 500
}

If i execute the exact same script in notepad it looks as its supposed to regardless of my Format > Line break option.
Perhaps you got some kind of odd settings in notepad, old version of ahk / notepad, no idea tbh.
Attachments
notepad.PNG
notepad.PNG (7.74 KiB) Viewed 635 times
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: How can I paste text containing linebreaks

01 Sep 2020, 04:59

Thanks I tested this out on MS word and it worked perfectly, seems to be an issue with the program I am trying to paste into.

Will have to live with it and use {enter} to simulate the line breaks.

Appreciate your help
James
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: How can I paste text containing linebreaks  Topic is solved

11 Feb 2021, 08:32

6 months later and I've figured out how to do it. Instead of using `n between lines I used `r`n and it worked perfectly.

Seems the program I was using doesn't allow `n for linebreaks but allows `r`n.

See below for example usage

Code: Select all

init := "1. text for line 1 bla bla bla bla`r`n2. text for line 2 bla bla bla bla `r`n"
paste(init) 

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333 and 272 guests