3

我使用了数千个 AHK 热字符串。例如(简化):

::btw::by the way

与大多数 AHK 用户不同,我允许的唯一 endkey 是\. 所以当我输入时btw\,我得到了by the way。空格键或回车键或其他此类键不会触发热字串。这样可以确保不会无意中触发热字符串。

现在,我也使用和弦。这是一个我的和弦的简化版本:

~t & g::
~g & t::
    SendInput {Backspace}
    SendInput {Space}the{Space}
    Return

这些和弦的工作方式是,如果我将手指按在tg键之间的边界上,AHK 类型the(包括前后的空格)非常有用。

现在,我想提高一个档次:我希望和弦自动触发热弦。例如,假设我想输入by the way the. 我可以打字btw\,然后t一起打字g。但是,如果我可以跳过反斜杠,而是让和弦自动触发热弦,那就更好了。(当然,只有在和弦之前的文本是热字符串的情况下。)

现在显然,我希望这不仅适用于btwand t+的这种特定组合g,而且适用于我大量收藏中的热弦和和弦的任何组合。

我怎样才能做到这一点?

(想到的一个想法是,AHK 可能有一个功能,它会在您每次按下结束键时启动,它的效果类似于“查看用户到目前为止键入的文本。它是热字符串吗?如果是这样执行它。”如果我有办法从我的和弦脚本中调用该函数,那将解决我的问题。但是,我不知道该怎么做。)

4

3 回答 3

1

你的问题让我很困扰,我一直在玩,直到找到一个似乎效果很好的解决方案:

#HotString *B0
SendMode, Input

endChars := "`n `t"
interruptChars := chr(8) ; 8 is BACKSPACE
counter := 33
while(counter <= 126)
{
    interruptChars .= chr(counter++)
}
Loop, Parse, endChars
{
    Hotkey, *~%A_LoopField%, FinishHotstring
}
Loop, Parse, interruptChars
{
    Hotkey, *~%A_LoopField%, InterruptHotString
}

; this is our pending hotstring replacement
pendingHS := ""
; this var will hold the number of BACKSPACEs needed
; to erase the input before replacing the hotstring
pendingBS := -1

Exit

::btw::
    pendingHS := "by the way"
    RegExMatch(A_ThisLabel, ":.*?:(.*)", abbr)
    pendingBS := StrLen(abbr1)
return

::bt::
    pendingHS := "Bluetooth"
    RegExMatch(A_ThisLabel, ":.*?:(.*)", abbr)
    pendingBS := StrLen(abbr1)
return

~t & g::
~g & t::
    if(pendingHS) {
        pendingBS++
        Send % "{BACKSPACE " pendingBS "}" pendingHS " the "
        pendingHS := ""
    } else {
        Send % "{BACKSPACE} the "
    }
Return

FinishHotstring:
    if(pendingHS) {
        pendingBS++
        Send, % "{BACKSPACE " pendingBS "}" pendingHS
        pendingHS := ""
    }
return

InterruptHotString:
    if(pendingHS) {
        pendingHS := ""
    }
return

遗憾的是,该解决方案与 AHK 热字符串标准相去甚远。一开始,您必须定义您的 customendChars和您的 custom interruptChars(当您的热字串实际上不是一个时,它们会告诉脚本,因为它会立即触发)。我使用了 BACKSPACE 和 ASCII 字符 33 到 126。
其余的不言自明:每个所谓的热字符串都已存储但尚未发送。如果触发了 anendChar或 achord或 an interruptChar,则脚本要么发送通常的热字符串替换,要么添加和弦附录,或者不做任何事情。

请讨论!

于 2013-06-13T21:51:22.303 回答
1

在花了大约 10 个小时之后,我决定放弃这个项目。除了所有常见的 AHK 可怕和错误之外,还有一个棘手的问题是,如果我输入I love the sunand 然后7同时u,我会得到I love the Sunday and而不是I love the sun and,因为 AutoHotKey 无法知道我不是故意的那个例子。

于 2013-06-14T18:26:50.673 回答
0

使用RegEx Powered Dynamic Hotstrings可能是您的一个选择。棘手的部分是确定文本是否是热字符串。可能保留所有东西的数组?下面是一些伪代码。

#Include DynamicHotstrings.ahk

hotstrings("(\w+)\\", "check")
Return

check:
    args := $1
    if (args = "btw") ; Ideally you would check an array to see if this was a hotstring
        msgbox % args ; SendInput
return

将热字串放入一个数组中可以简单地手动维护它们,解析你的脚本,甚至使用这样的脚本

我希望这能为您指明正确的方向。

于 2013-06-13T18:11:59.373 回答