【问题标题】:Quickly send long text in AutoHotkey在 AutoHotkey 中快速发送长文本
【发布时间】:2015-02-08 08:36:39
【问题描述】:

我一直在试图弄清楚如何更快地插入/扩展长文本。我目前使用的击键方法非常耗时,因此我宁愿避免。

目前我正在使用以下方法:

::abc::all bad cats

或者对于更长的文本:

::li::
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

但是第二种方法有点慢。

对于如何避免这种缓慢的扩展方法有什么建议吗?也许通过使用剪贴板从 AHK 脚本中复制和粘贴?

【问题讨论】:

    标签: text autohotkey


    【解决方案1】:
    ::li::  
    text =
    (
    Line1
    Line2
    ...
    )
    ; IfWinActive, ahk_group textEditors ; create a group in the auto execute section
    SendInput, %text%                      ;  SendInput is faster and more reliable
    return
    

    或

    ::li::
    ; IfWinActive, ahk_group textEditors
    SendInput,
    (
    Line1
    Line2
    ...
    )
    return
    

    【讨论】:

    • 非常感谢!但不知何故,我似乎并不比我以前使用的标准方法快。我需要对 agh 脚本进行任何调整吗?
    • 我可以确认,SendInput 对于长文本的性能很差,有时字符会混淆。
    【解决方案2】:

    试试这个:

    ::li::
    ClipSaved := ClipboardAll ; save the entire clipboard to the variable ClipSaved
    clipboard := ""           ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
    clipboard =               ; copy this text:
    (
    Lorem ipsum dolor ...
    line2
    ..
    )
    ClipWait, 2              ; wait max. 2 seconds for the clipboard to contain data. 
    if (!ErrorLevel)         ; If NOT ErrorLevel, ClipWait found data on the clipboard
        Send, ^v             ; paste the text
    Sleep, 300
    clipboard := ClipSaved   ; restore original clipboard
    ClipSaved =              ; Free the memory in case the clipboard was very large.
    return
    

    https://autohotkey.com/docs/misc/Clipboard.htm

    【讨论】:

    • ClipWait 被注释掉是有原因的吗? AHK's documentation 说它提高了脚本的可靠性。
    【解决方案3】:

    另一种使用自动热键脚本语言发送快速长文本的方法是,

    如果您将所有文本首先放入 Windows 注册表内存。

    然后你可以用[Registry Ram Memory Speed]读取它到[Clipboard Memory]粘贴它就完成了。

    你可以试试这个代码:

    Example1.ahk:

    ; [^ = Ctrl] [+ = Shift] [! = Alt] [# = Win]
    #SingleInstance Force
    
    ;Variant 1
    ;put any clipboard text into variable a1
    ;send ^c
    ;a1=%clipboard%
    
    ;Variant 2
    ;or put any Variable to variable a1
    ;a1 := "Any Text"
    
    ;Variant 3
    ;or put any File text to variable a1
    FileRead, a1, C:\My File1.txt
    FileRead, a2, C:\My File2.txt
    
    ;Write the variable's To Registry - KeyHintText,value1 to value2
    RegWrite, REG_SZ, HKEY_CURRENT_USER, software\KeyHintText,value1,%a1%
    RegWrite, REG_SZ, HKEY_CURRENT_USER, software\KeyHintText,value2,%a2%
    
    :*:abc:: 
    clipboard := a1
    send ^v
    return
    
    :*:def:: 
    clipboard := a2
    send ^v
    return
    

    注意 - :*:abc:: = (你可以输入 abc 不带空格) - ::abc:: = (你可以输入 abc 带空格)

    如果您使用 Windows 注册表,那么优点是:

    1 - 如果注册表中的 Value1 文本已更改,则将其与相同的热键一起使用 :*:abc::

    :*:abc:: 
    RegRead, clipboard, HKEY_CURRENT_USER,software\KeyHintText,value1
    send ^v
    return
    

    2 - 如果您重新启动计算机,所有文本都会自动保存到 RAM 内存中。

    您只能使用此代码

    example2.ahk

    ; [^ = Ctrl] [+ = Shift] [! = Alt] [# = Win]
    #SingleInstance Force
    
    ;read the Variable's From Windows Registry
    RegRead, a1, HKEY_CURRENT_USER,software\KeyHintText,value1 
    RegRead, a2, HKEY_CURRENT_USER,software\KeyHintText,value2
    
    :*:abc:: 
    clipboard := a1
    send ^v
    return
    
    :*:def:: 
    clipboard := a2
    send ^v
    return
    

    提示:我使用它与Buttoncommander 软件一起,然后您可以在 Windows 桌面上制作一组可点击图片(工具栏),您可以将例如 abc 文本替换为图片,如果您使用鼠标或推送这些图片触摸设备它将执行(本机)自动热键命令代码。

    【讨论】:

    • 是否有原因未将其标记为正确答案?多么美妙的彻底和写得很好的回应。这涵盖了如此多的场景,并为新(甚至是中等)用户提供了很多有用的信息。肯定 +1 编辑:如果这是您给出的回复,非常欢迎您访问 Reddit.com 上的 /r/AutoHotkey subreddit 访问我们。我们一直在寻找新的、消息灵通和积极的贡献者来帮助大众。
    猜你喜欢
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多