如何使用Autoit/Autohotkey模仿Visual Studio的“Ctrl-K,C”两步宏行为?
问题描述:
我试图建立AutoHotkey宏一些常见的任务,我想热键模仿Visual Studio的“两步走快捷方式”的行为 - 即按Ctrl键 - ķ将使“微距模式”;在微距模式下,按某些键将运行一个宏,然后禁用“微距模式”,其他任何键都将禁用微距模式。如何使用Autoit/Autohotkey模仿Visual Studio的“Ctrl-K,C”两步宏行为?
示例 - 输入一个文件名时,我希望能够通过点击Ctrl键插入今天的日期 - ķ,然后按d。
有没有人有一个有状态的AutoHotkey脚本的行为像这样的很好的例子?
答
这AutoHotkey的脚本,当您按下CTRL +ķ,会等你按一个键,如果按下d,它会输入当前日期。
^k::
Input Key, L1
FormatTime, Time, , yyyy-MM-dd
if Key = d
Send %Time%
return
答
接受的答案略有变化 - 这是我最终使用的。我正在捕获Ctrl + LWin(左侧的Windows键),因此它不会与VS内置的Ctrl-K快捷键冲突。
; Capture Ctrl+Left Windows Key
^LWin::
; Show traytip including shortcut keys
TrayTip, Ctrl-Win pressed - waiting for second key..., t: current time`nd: current date, 1, 1
; Capture next string input (i.e. next key)
Input, Key, L1
; Call TrayTip with no arguments to remove currently-visible traytip
TrayTip
if Key = d
{
FormatTime, Date, , yyyyMMdd
SendInput %Date%
}
else if Key = t
{
FormatTime, Time, , hhmmss
SendInput %Time%
}
return