我怎样才能模仿Visual Studio的“ Ctrl-K,C”使用Autoit / Autohotkey的两步宏行为?

StackOverflow https://stackoverflow.com/questions/200587

  •  03-07-2019
  •  | 
  •  

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

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

有没有人有一个好主意的AutoHotkey脚本的例子呢?

有帮助吗?

解决方案

当您按 ctrl + k 时,此Autohotkey脚本将等待您按一个键,如果按 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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top