你的问题让我很困扰,我一直在玩,直到找到一个似乎效果很好的解决方案:
#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
,则脚本要么发送通常的热字符串替换,要么添加和弦附录,或者不做任何事情。
请讨论!