在AHK上创建文本宏系统

时间:2016-07-29 06:39:36

标签: macros autohotkey

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

hi =
(
Hello, 

Some more text
)

Hotstring

::\hi::
Macro(hi)
return

功能Macro

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

使用剪贴板功能的原因是因为长文本块在打印之前往往有延迟,这是该功能不会出现的问题。

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

您能否向我提供代码示例或给出我应该查看的内容?

1 个答案:

答案 0 :(得分:1)

有几个动态热门字符串AutoHotkey功能,但这可能是您要Hotstring使用的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
}

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

相关问题