【问题标题】:How to send line by line data from a .txt file using autohotkey?如何使用自动热键从 .txt 文件中逐行发送数据?
【发布时间】:2014-10-12 18:12:32
【问题描述】:

亲爱的朋友们,我正在尝试使用自动热键中的循环(读取文件内容)命令将数据从 .txt 文件发送到另一个文件。但它不是逐行发送,即连续发送。正如我制作的脚本如下-

F1::

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

在上面的示例中,我将 F1 设为热键。

我的D: 驱动器中有一个data.txt 文件。现在我希望当我按下 F1 键时,它应该一次只从data.txt 文件发送一行。当我再次按下 F1 键时,它应该从该文件发送下一行,依此类推。但它没有这样做。它正在小跑(连续)上从data.txt 文件发送数据,直到文件结束。

请朋友们建议我解决这个问题。

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    您可以在热键之外加载文件数据,然后在热键内部循环并获取相应的行。不过,我不确定这对于大文件会有多快。

    ; 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
    

    【讨论】:

      猜你喜欢
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2022-01-11
      • 1970-01-01
      • 2019-04-21
      • 2023-01-03
      • 1970-01-01
      相关资源
      最近更新 更多