issue with SendEvent Clipboard Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
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

gosub SendClipboardTextCharacters


        SendEvent % StrReplace(Clipboard,"`r")

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


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

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
Posts: 1298
Joined: 02 Oct 2015, 12:15

Re: issue with SendEvent Clipboard  Topic is solved

24 Jun 2018, 18:43

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

User avatar
Posts: 1333
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 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?
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
Posts: 5746
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
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”

Who is online

Users browsing this forum: AHKStudent, kaashif, MannyKSoSo, Scr1pter and 44 guests