1
votes

Dear friends I am trying to send data from a .txt file to some another file by using Loop (read file contents) command in autohotkey. But it is not sending it line by line i.e. it is sending it continuously. As I made a script which is as follows-

F1::

Loop, read, C:\Data.txt
{
    Loop, parse, A_LoopReadLine, %A_Tab%
    {
        Send %A_LoopField%
    }
}

In the above example I made F1 a hotkey.

There is a data.txt file in my D: drive. Now I want that when I press F1 key it should send only one line at a time from data.txt file. When I again press F1 key, it should send next line from that file and so on. But it is not doing so. It is sending the data from data.txt file on the trot (continuously) till the end of the file.

Friends kindly suggest me any solution of this problem.

1

1 Answers

0
votes

You can load the file-data outside the hotkey, then loop through it inside the hotkey and get the appropriate line. I'm not sure how fast this would be with huge files though.

; Uncomment this to load data from a file
;FileRead, fileData, C:\data.txt

; This is only for testing
fileData =
(LTrim
    Line one
    Line two
    Line three
)

; Init lineIndex to 1
lineIndex := 1

F1::
    Loop, Parse, fileData, `n
    {
        ; A_Index holds the current loop-itteration
        if (A_Index == lineIndex) {
            SendInput, %A_LoopField%
            ; Increment lineIndex
            lineIndex++
            break
        }
    }
return

Esc::ExitApp