Get specific line to clipboard

Ask gaming related questions (AHK v1.1 and older)
WackJoe
Posts: 10
Joined: 05 Jul 2022, 20:29

Get specific line to clipboard

Post by WackJoe » 05 Jul 2022, 20:40

So im playing with making a macro to help me load a character easyer in a Warcraft3 RPG. The way the loading process works is that i must first type -lc then 1 half og my code, then 2nd half of my code and end with -le.

The -lc / -le part is pretty straight forward. However when it comes to grabbing a specific line, AND a specific place in that line, and copy it to the clipboard, i must admit that this is way of of my league.

So in line 52 of my saved .txt file i have this load code:

Code: Select all

call Preload( "-l WiD0-4koh-Di!m-%Km@-2CA9-1^Ip-y@fk-JjLR-7nrW-pb@s-e6GH-eIyI-A6JS-7X3W-5KcF-Qxs7-FhKa-8p2E-nwU7-C$aH-!M%a-aU0m-ugb@-L^2v-28fZ-KBCN-V2iB-VOPi-b" )
And basicly what i want it to do, is to take this code, cut it in half and paste it in 2 different lines. Like this:

Code: Select all

F6::

		Clipboard := "-lc"
		ClipWait, 200
		SendInput {Enter}^v{Enter}
		Sleep, 200
		Clipboard := "WiD0-4koh-Di!m-%Km@-2CA9-1^Ip-y@fk-JjLR-7nrW-pb@s-e6GH-eIyI-A6JS-7X3W-"
		ClipWait, 200
		SendInput {Enter}^v{Enter}
		Sleep, 200
		Clipboard := "5KcF-Qxs7-FhKa-8p2E-nwU7-C$aH-!M%a-aU0m-ugb@-L^2v-28fZ-KBCN-V2iB-VOPi-b"
		ClipWait, 200
		SendInput {Enter}^v{Enter}
		Sleep, 200
		SendInput {Enter}-le{Enter}
		Sleep, 200

return
[Mod edit: Changed quote tags to [code][/code] tags.]

Anyone who can help out, or point me in the right direction?

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Get specific line to clipboard

Post by mikeyww » 05 Jul 2022, 21:05

Welcome to this AutoHotkey forum!

Code: Select all

file    = %A_ScriptDir%\test.txt
lineNum = 52
If !FileExist(file)
 MsgBox, 48, Error, File not found.`n`n%file%

F6::
FileReadLine, line, %file%, %lineNum%
RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
Send `n-lc`n
Sleep, 200
SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
Sleep, 200
SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
Sleep, 200
Send `n-le`n
Return

WackJoe
Posts: 10
Joined: 05 Jul 2022, 20:29

Re: Get specific line to clipboard

Post by WackJoe » 05 Jul 2022, 21:55

mikeyww wrote:
05 Jul 2022, 21:05
Welcome to this AutoHotkey forum!

Code: Select all

file    = %A_ScriptDir%\test.txt
lineNum = 52
If !FileExist(file)
 MsgBox, 48, Error, File not found.`n`n%file%

F6::
FileReadLine, line, %file%, %lineNum%
RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
Send `n-lc`n
Sleep, 200
SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
Sleep, 200
SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
Sleep, 200
Send `n-le`n
Return
You Sir, are a true legend. This is EXACTLY what i needed! Thanks alot!!

WackJoe
Posts: 10
Joined: 05 Jul 2022, 20:29

Re: Get specific line to clipboard

Post by WackJoe » 05 Jul 2022, 22:16

@mikeyww

I do however have 1 queston. Would i have to run several AHK scripts to be able to do this with several characters? Can't seem to get it to work with more than 1..

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Get specific line to clipboard

Post by mikeyww » 05 Jul 2022, 22:29

I have no idea what files are actually being generated or what it would mean to do with several characters, but AHK can read as many files or lines as needed.

WackJoe
Posts: 10
Joined: 05 Jul 2022, 20:29

Re: Get specific line to clipboard

Post by WackJoe » 05 Jul 2022, 22:32

mikeyww wrote:
05 Jul 2022, 22:29
I have no idea what files are actually being generated or what it would mean to do with several characters, but AHK can read as many files or lines as needed.
So i tryed this. Its 2 sepperate files. And this didnt seem to work. It would load the character assigned to "file1" on both commands.

Code: Select all


file1    = C:\Users\Lund\Documents\Warcraft III\CustomMapData\Twilight's Eve Evo\WackJoe#2950\Prophetess\[Level 300].txt
lineNum = 52
If !FileExist(file1)
 MsgBox, 48, Error, File not found.`n`n%file1%

F6::
FileReadLine, line, %file1%, %lineNum%
RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
Send `n-lc`n
Sleep, 200
SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
Sleep, 200
SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
Sleep, 200
Send `n-le`n
Return


file2    = C:\Users\Lund\Documents\Warcraft III\CustomMapData\Twilight's Eve Evo\WackJoe#2950\Jounin\[Level 300].txt
lineNum = 52
If !FileExist(file2)
 MsgBox, 48, Error, File not found.`n`n%file2%

F7::
FileReadLine, line, %file2%, %lineNum%
RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
Send `n-lc`n
Sleep, 200
SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
Sleep, 200
SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
Sleep, 200
Send `n-le`n
Return

WackJoe
Posts: 10
Joined: 05 Jul 2022, 20:29

Re: Get specific line to clipboard

Post by WackJoe » 05 Jul 2022, 23:29

So i figured it out. All i had to do was rearange a few things. This is my end result. Thanks again @mikeyww !

Code: Select all

#NoEnv  
; #Warn  
SendMode Input  
SetWorkingDir %A_ScriptDir%  
#IfWinActive, Warcraft III


file1    = C:\Users\Lund\Documents\Warcraft III\CustomMapData\Twilight's Eve Evo\WackJoe#2950\Prophetess\[Level 300].txt
file2    = C:\Users\Lund\Documents\Warcraft III\CustomMapData\Twilight's Eve Evo\WackJoe#2950\Jounin\[Level 300].txt
lineNum = 52

If !FileExist(file1)
 MsgBox, 48, Error, File not found.`n`n%file1%

;//////////// Prophetess Load ////////////

F6::
Send `nLoading Prophetess:`n
Sleep, 100
FileReadLine, line, %file1%, %lineNum%
RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
Send `n-lc`n
Sleep, 100
SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
Sleep, 100
SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
Sleep, 100
Send `n-le`n
Return

;//////////// Jounin Load ////////////

If !FileExist(file2)
 MsgBox, 48, Error, File not found.`n`n%fil2e%

F7::
Send `nLoading Jounin:`n
Sleep, 100
FileReadLine, line, %file2%, %lineNum%
RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
Send `n-lc`n
Sleep, 100
SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
Sleep, 100
SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
Sleep, 100
Send `n-le`n
Return

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Get specific line to clipboard

Post by BoBo » 05 Jul 2022, 23:47

Code: Select all

#NoEnv  
; #Warn  
SendMode Input  
SetWorkingDir %A_ScriptDir%  
#IfWinActive, Warcraft III

path := "C:\Users\Lund\Documents\Warcraft III\CustomMapData\Twilight's Eve Evo\WackJoe#2950"
file1 := "Prophetess\[Level 300].txt”
file2 := "Jounin\[Level 300].txt"

F6::func("Prophetess", path "\" file1)
F7::func("Jounin", path "\" file2)

func(name, file) {
	If !FileExist(file)
 		MsgBox, 48, Error, File not found.`n`n%file%

	Send % "`nLoading " name ":`n"
	Sleep, 100
	FileReadLine, line, %file%, 52
	RegExMatch(line, "-l \K[^""]+", str), pos := StrLen(str) // 2
	Send `n-lc`n
	Sleep, 100
	SendInput % "{Text}`n" SubStr(str, 1, pos ) "`n"
	Sleep, 100
	SendInput % "{Text}`n" SubStr(str, pos + 1) "`n"
	Sleep, 100
	Send `n-le`n
	Return
	}
	
#If

Post Reply

Return to “Gaming Help (v1)”