issue with SendEvent Clipboard Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Prisonfeed
Posts: 8
Joined: 24 Aug 2017, 10:59

issue with SendEvent Clipboard

24 Jun 2018, 15:17

I have a Windows program that I like to paste to quite often. However it doesn't allow pasting, so I use AHK as follows...

Code: Select all

F4::
gosub SendClipboardTextCharacters
return

SendClipboardTextCharacters:

        SetKeyDelay,10
        SendEvent % StrReplace(Clipboard,"`r")

return
It removes the 'r because Windows likes to use 'r'n which results in double line returns. Everything was great, but now the program has updated. All the lines become indented (a built in "Feature" in the software). One way I can get around this awful "feature", which can't be disabled, is to hit the HOME key after every line return.

I tried replacing 'r'n with 'n{home}.

Code: Select all

SendClipboardTextCharacters:

        SetKeyDelay,10
        SendEvent % StrReplace(Clipboard,"`r{home}")

return
This does return the cursor to the front of the line, however it writes {home} at the front of every line.

First Line
{home}Line 2
{home}line 3
{home}line 4



How can I sent a HOME key press after every line return without actually writing {home} at the front of every line?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: issue with SendEvent Clipboard  Topic is solved

24 Jun 2018, 18:43

Try:
SendEvent % StrReplace(Clipboard,"`r") . "{Home}"

HTH
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: issue with SendEvent Clipboard

24 Jun 2018, 19:11

Prisonfeed wrote:I tried replacing 'r'n with 'n{home}
Good pseudo code, but that's not reflected in the snippet you posted. It may even be better to replace it with 'n+{home} so you select the indentation whitespace characters, which will get overwritten, opposed to aggregating at the end of your 'pasted' text: SendEvent % StrReplace(Clipboard,"`r`n","`r+{home}")
however it writes {home} at the front of every line
Does the clipboard text happen to have the string {Raw} or {Text} on the first line?
Prisonfeed
Posts: 8
Joined: 24 Aug 2017, 10:59

Re: issue with SendEvent Clipboard

24 Jun 2018, 20:08

Woohoo!! That did it!!!

I tried a dozen different ways, and I just could not get it to work.

Thank YOU!!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: issue with SendEvent Clipboard

24 Jun 2018, 21:12

I would imagine that something like this would avoid any issues with sending special characters:

Code: Select all

q:: ;send text while deleting leading whitespace generated by a program
vText := "a`r`nb`r`nc`r`nd`r`ne"

;note: {Text} requires AHK v1.1.27+
Loop, Parse, vText, `n, `r
{
	if !(A_Index = 1)
		SendInput, {Enter}+{Home}
	SendInput, % "{Text}" A_LoopField
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 351 guests