【问题标题】:Creating text macro system on AHK在 AHK 上创建文本宏系统
【发布时间】:2016-07-30 19:06:48
【问题描述】:

我是 AutoHotKey 的新手,我正在尝试制作我的宏系统。目前我有一个看起来像这样的系统: 我有文本变量

hi =
(
Hello, 

Some more text
)

一个热字串

::\hi::
Macro(hi)
return

还有一个函数Macro

Macro(text)
{
ClipSaved := ClipboardAll       ; save clipboard
clipboard := text
ClipWait
Sleep, 150
Send, ^v
clipboard := ClipSaved       ; restore original clipboard
return
}

将函数与剪贴板一起使用的原因是,长文本块在打印出来之前往往会有延迟,而函数不会出现这个问题。

我发现了一个名为动态热字符串的概念,我想我可以以某种方式实现它,这样我就不必为每个文本字段编写第二个显示块,而是有一个 one 热字符串会明白,如果我的输入以\ 开头,并且脚本中有一个变量名为x,它应该执行Macro(x),但我从未找到任何类似的例子。

您能否为我提供代码示例或提供任何我应该检查的线索?

【问题讨论】:

    标签: macros autohotkey


    【解决方案1】:

    有几个动态的 Hotstring AutoHotkey 函数,但这可能是你想要使用的一个 Hotstring by menixator

    所以你需要下载 hotstring.ahk 并像示例中一样#include 它。

    #SingleInstance, force
    #include Hotstring.ahk
    
    hi=
    (
    Hello,
    
    Some more text
    )
    
    bye=
    (
    So long,
    
    Some more text
    )
    
    Hotstring("/hi", "Paste")
    Hotstring("/bye", "Paste")
    return
    
    Paste:
    text:=Trim($,"/") ; we need to get rid of the leading /
    text:=% %text%      ; and need to dereference it
    Macro(text) 
    Return
    
    Macro(text)
    {
    ClipSaved := ClipboardAll       ; save clipboard
    Clipboard := text
    ClipWait
    Sleep, 150
    Send, ^v
    clipboard := ClipSaved       ; restore original clipboard
    return
    }
    

    有一些更优雅的方法可以做到这一点,尤其是变量,例如,您可以将它们存储在全局对象(关联数组)中,但这应该可以帮助您。

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 2015-09-23
      • 2010-11-02
      • 2010-09-20
      • 1970-01-01
      • 2013-09-28
      • 2015-04-09
      • 1970-01-01
      相关资源
      最近更新 更多