How to copy and paste a line at a time Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hieveryone
Posts: 43
Joined: 28 Nov 2022, 01:31

How to copy and paste a line at a time

06 Sep 2023, 05:59

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 :D
hieveryone
Posts: 43
Joined: 28 Nov 2022, 01:31

Re: How to copy and paste a line at a time

06 Sep 2023, 06:00

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.]
User avatar
mikeyww
Posts: 27310
Joined: 09 Sep 2014, 18:38

Re: How to copy and paste a line at a time  Topic is solved

06 Sep 2023, 21:29

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] : ''
 }
}
User avatar
flyingDman
Posts: 2843
Joined: 29 Sep 2013, 19:01

Re: How to copy and paste a line at a time

06 Sep 2023, 22:49

or:

Code: Select all

arr := strsplit(a_clipboard,"`n","r")
^v::(arr.length) && sendtext(arr.removeat(1))
if you want to "reload" at the end use:

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
hieveryone
Posts: 43
Joined: 28 Nov 2022, 01:31

Re: How to copy and paste a line at a time

07 Sep 2023, 04:14

mikeyww wrote:
06 Sep 2023, 21:29

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] : ''
 }
}
Wow that works. Do you have any solution to say if I was instead of the clipboard, was going to use an external txt?
or no
User avatar
mikeyww
Posts: 27310
Joined: 09 Sep 2014, 18:38

Re: How to copy and paste a line at a time

07 Sep 2023, 04:44

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] : ''
 }
}
User avatar
flyingDman
Posts: 2843
Joined: 29 Sep 2013, 19:01

Re: How to copy and paste a line at a time

07 Sep 2023, 06:17

or

Code: Select all

str := fileread(A_ScriptDir "\sample.txt")
arr := strsplit(str,"`n","`r")
^v::(arr.length) && sendtext(arr.removeat(1))
in case you want to "reload" at the end:

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

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 39 guests