Page 1 of 1

How can I paste text containing linebreaks

Posted: 28 Aug 2020, 05:42
by JKnight_xbt33
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

Re: How can I paste text containing linebreaks

Posted: 28 Aug 2020, 06:01
by BoBo

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'

Re: How can I paste text containing linebreaks

Posted: 28 Aug 2020, 06:02
by RubbeH
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
}

Re: How can I paste text containing linebreaks

Posted: 31 Aug 2020, 16:56
by JKnight_xbt33
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 112 times

Re: How can I paste text containing linebreaks

Posted: 31 Aug 2020, 17:01
by BoBo
So, you've enabled Notepad's Format > Line Break-option already?? :wtf:

Re: How can I paste text containing linebreaks

Posted: 31 Aug 2020, 17:16
by rommmcek
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

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

Posted: 01 Sep 2020, 00:32
by RubbeH
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.

Re: How can I paste text containing linebreaks

Posted: 01 Sep 2020, 04:59
by JKnight_xbt33
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