15

我正在尝试为一些常见任务设置AutoHotkey宏,并且我希望热键模仿 Visual Studio 的“两步快捷方式”行为 - 即按下Ctrl-K将启用“宏模式”;在宏模式下,按某些键将运行宏然后禁用“宏模式”,任何其他键只会禁用宏模式。

示例 - 输入文件名时,我希望能够通过点击Ctrl-插入今天的日期K,然后按D

有没有人有一个像这样行为的有状态 AutoHotkey 脚本的好例子?

4

2 回答 2

9

这个 Autohotkey 脚本,当你按下ctrl+时k,将等待你按下一个键,如果你按下d,它将输入当前日期。

^k::
Input Key, L1
FormatTime, Time, , yyyy-MM-dd
if Key = d
    Send %Time%
return
于 2008-10-14T16:57:37.693 回答
6

接受的答案略有不同 - 这就是我最终使用的。我正在捕获 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
于 2008-10-15T08:41:25.933 回答