AutoHotKey:获得一个和弦来引发一个热弦

时间:2013-06-13 13:12:44

标签: keyboard autohotkey chord

我使用了数以千计的AHK热弦。例如(简化):

::btw::by the way

与大多数AHK用户不同,我允许的唯一端键是\。因此,当我输入btw\时,我会得到by the way。空格或输入或其他此类键引发热字符串。这可确保热字串永远不会无意中引发。

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

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

这些和弦的工作方式是,如果我将手指放在tg键之间的边框上,则AHK键入the(包括前后空格。)是有用的。

现在,我想把它提升一个档次:我希望和弦自动引发热弦。例如,假设我要输入by the way the。我可以一起输入btw\,然后输入tg。但是,如果我可以跳过反斜杠会更好,而是让和弦自动引发热弦。 (当然,紧接在和弦之前的文本是热弦的情况下。)

现在很明显,我希望这不仅适用于btwt + g的特定组合,而且适用于我的大集合中的热字符串和和弦的任意组合。< / p>

我该怎么做?

(我想到的一个想法是,AHK可能有一个函数,每当你点击一个endkey时就会启动它,这会影响到“看看用户输入的文本到目前为止。这是一个热点串?如果是这样,请执行它。“如果我只能从我的和弦脚本中调用该函数,那将解决我的问题。但是,我不知道该怎么做。”

3 个答案:

答案 0 :(得分: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热绳的标准。开始时,您必须定义自定义endChars以及自定义interruptChars(当您的hotstring实际上不是一个时,它们会告诉脚本,因为它会立即触发)。我使用了BACKSPACE和ASCII字符33到126 其余的都是不言自明的:每个被指控的hotstring都存储起来,但尚未发送。如果触发endCharchordinterruptChar,则脚本会发送通常的热字符串替换或添加和弦附录或不执行任何操作。

请讨论!

答案 1 :(得分: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

将热字符串放入数组可能只是手动维护它们,解析脚本,甚至使用像this这样的脚本。

我希望这能指出你正确的方向。

答案 2 :(得分:0)

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