ControlSend sends extra newlines Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

ControlSend sends extra newlines

13 Aug 2018, 12:34

I am trying to send a text to notepad with ControlSend. But it sends a text with the extra newline to notepad. I think this problem caused by ControlSend.

Code: Select all

append()
{
SetKeyDelay, 10, 10
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}

Code: Select all

#If GetKeyState("Ctrl") && GetKeyState("Shift") ;Seçilileri dosyay kaydeder.
{
a & s::
sleep 30
Send, ^c
sleep 30
Clipboard := "`n[source]`n----`n" . Clipboard . "`n---- `n`n"
sleep 30
append()
sleep 30
Return
}

It sends this:
> [source,java]
> ----
> SetKeydelay, 10, 10
>
> SetKeyDelay, 0, 10
>
> SetKeyDelay, 0, 10
> ----
Instead of this:
> [source,java]
> ----
> SetKeydelay, 10, 10
> SetKeyDelay, 0, 10
> SetKeyDelay, 0, 10
> ----
User avatar
Scr1pter
Posts: 498
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: ControlSend sends extra newlines

14 Aug 2018, 04:58

Well, then try to get rid of some `n in this part of your code:

Code: Select all

Clipboard := "`n[source]`n----`n" . Clipboard . "`n---- `n`n"
Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

Re: ControlSend sends extra newlines

14 Aug 2018, 08:56

Really?It sends newline even though there is no newline in the Clipboard.
User avatar
Scr1pter
Posts: 498
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: ControlSend sends extra newlines

14 Aug 2018, 09:01

What happens if you delete this line?

Code: Select all

Clipboard := "`n[source]`n----`n" . Clipboard . "`n---- `n`n"
Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

Re: ControlSend sends extra newlines

14 Aug 2018, 09:21

Scr1pter wrote:What happens if you delete this line?

Code: Select all

Clipboard := "`n[source]`n----`n" . Clipboard . "`n---- `n`n"
Regards
I tried this way but I have still extra lines

Code: Select all

sleep 30
Send, ^c
sleep 30
ControlSendRaw,Scintilla2,`n[source]`n----`n,ahk_class Notepad++
ControlSendRaw,Scintilla2,%Clipboard%,ahk_class Notepad++	
ControlSendRaw,Scintilla2,`n---- `n,ahk_class Notepad++
Return

I tried this way strangely I have extra "}" at the end of the cursor. I think the problem is caused by % % .Is there way to send a text without % %?

Code: Select all

sleep 30
Send, ^c
sleep 30
ControlSendRaw,Scintilla2,`n[source]`n----`n,ahk_class Notepad++
ControlSendRaw,Scintilla2,%Clipboard%,ahk_class Notepad++
Loop, parse, Clipboard,`n
	{	
        ControlSendRaw,Scintilla2,%A_LoopField%,ahk_class Notepad++
	}	
ControlSendRaw,Scintilla2,`n---- `n,ahk_class Notepad++
Return
colt
Posts: 72
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: ControlSend sends extra newlines

14 Aug 2018, 13:03

What are the contents of your clipboard? I had some other strange behavior when I tried the code myself.

Code: Select all

ouput := "TEST"
f6::
ControlSendRaw,Scintilla1,`n[source]`n----`n,ahk_class Notepad++
ControlSendRaw,Scintilla1,%ouput%,ahk_class Notepad++	
ControlSendRaw,Scintilla1,`n---- `n,ahk_class Notepad++
Return
The output in notepad. It seems to skip the return in the last line every time after the first time it is run.

Code: Select all

[source]
----
TEST
---- 

[source]
----
TEST----
I tried combining the text into a single string, I still have this strange problem. What version of notepad++ are you using?
I noticed the output is always correct the first time it is sent to the control. The rest will be incorrect. Deleting the content of the control somehow resets the pattern.
I think there is a problem with notepad++ because it works okay in notepad.exe
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

Re: ControlSend sends extra newlines  Topic is solved

14 Aug 2018, 13:08

`r`n are all translated to a single Enter keystroke, unlike normal mode and Raw mode, which translate `r`n to two Enter keystrokes.

When we copy Windows new-line sequence: `r`n. It sends this :
....
[source,java]
----
aaa
bbb
ccc
----
....

Insteads of this:
....
[source,java]
----
a

b

c

----
....



* We have to convert `r`n to `n with StrReplace then ControlSend therefore Send will not interpret two line.
Clipboard := StrReplace(Clipboard,"`r`n","`n")


a & j::
sleep 30
Send, ^c
sleep 30
ControlSendRaw,Edit1,`n[source]`n----`n,ahk_class Notepad
sleep 3000
aas := StrReplace(Clipboard,"`r`n","`n")
ControlSendRaw,Edit1,%aas%,ahk_class Notepad
sleep 3000
ControlSendRaw,Edit1,`n----`n,ahk_class Notepad
sleep 3000
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Google [Bot] and 65 guests