Sorry for my basic understanding of code,
I have already viewed this topic,viewtopic.php?t=84738, but it didn't seem to work. Maybe it's an old version?
So basically all I want is :
When I press a key, it copies the first line from another txt.
When I press the key again, it copies the second line, and so on.
Thank you in advanced
How to copy and paste a line at a time Topic is solved
-
- Posts: 43
- Joined: 28 Nov 2022, 01:31
-
- Posts: 43
- Joined: 28 Nov 2022, 01:31
Re: How to copy and paste a line at a time
Whoops I just realized I did it on v1 It was meant to be v2 I'm pretty sure (well I'm not certain but I'm most certain that I'm using the latest version)
[Mod action: Moved topic to AHK v2 help.]
[Mod action: Moved topic to AHK v2 help.]
Re: How to copy and paste a line at a time Topic is solved
Code: Select all
#Requires AutoHotkey v2.0
A_Clipboard := "
(
1
2
3
4.25
5.25
)"
^v::A_Clipboard := pasteFirstLine(A_Clipboard)
pasteFirstLine(str) {
If str != '' {
SendText (arr := StrSplit(str, '`n', '`r', 2))[1]
Return arr.Length = 2 ? arr[2] : ''
}
}
- flyingDman
- Posts: 2843
- Joined: 29 Sep 2013, 19:01
Re: How to copy and paste a line at a time
or:
if you want to "reload" at the end use:
Code: Select all
arr := strsplit(a_clipboard,"`n","r")
^v::(arr.length) && sendtext(arr.removeat(1))
Code: Select all
arr := strsplit(a_clipboard,"`n","r"), len := arr.length
^v::sendtext(x := arr.removeat(1)),arr.insertat(len,x)
14.3 & 1.3.7
-
- Posts: 43
- Joined: 28 Nov 2022, 01:31
Re: How to copy and paste a line at a time
Wow that works. Do you have any solution to say if I was instead of the clipboard, was going to use an external txt?mikeyww wrote: ↑06 Sep 2023, 21:29Code: Select all
#Requires AutoHotkey v2.0 A_Clipboard := " ( 1 2 3 4.25 5.25 )" ^v::A_Clipboard := pasteFirstLine(A_Clipboard) pasteFirstLine(str) { If str != '' { SendText (arr := StrSplit(str, '`n', '`r', 2))[1] Return arr.Length = 2 ? arr[2] : '' } }
or no
Re: How to copy and paste a line at a time
Code: Select all
; This script pastes lines from a file, one line at a time
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'
^v:: {
Static str := ''
If str = ''
If FileExist(filePath)
str := FileRead(filePath)
Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
str := pasteFirstLine(str)
}
pasteFirstLine(str) {
If str != '' {
SendText (arr := StrSplit(str, '`n', '`r', 2))[1]
Return arr.Length = 2 ? arr[2] : ''
}
}
- flyingDman
- Posts: 2843
- Joined: 29 Sep 2013, 19:01
Re: How to copy and paste a line at a time
or
in case you want to "reload" at the end:
Code: Select all
str := fileread(A_ScriptDir "\sample.txt")
arr := strsplit(str,"`n","`r")
^v::(arr.length) && sendtext(arr.removeat(1))
Code: Select all
str := fileread(A_ScriptDir "\sample.txt")
arr := strsplit(str,"`n","`r"), len := arr.length
^v::sendtext(x := arr.removeat(1)),arr.insertat(len,x)
14.3 & 1.3.7
Who is online
Users browsing this forum: No registered users and 39 guests