How can I paste text containing linebreaks Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
JKnight_xbt33
Posts: 112
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: 3861
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: 44
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: 112
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 109 times
BoBo
Posts: 3861
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: 1123
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: 44
Joined: 13 Jul 2020, 08:40

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

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 81 times
JKnight_xbt33
Posts: 112
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

Return to “Ask For Help”

Who is online

Users browsing this forum: +MeleaB+, 99marvel, bautai, mikeyww, TAC109, torontob, zhainv2013 and 43 guests