2008-10-14 38 views
14

我試圖建立AutoHotkey宏一些常見的任務,我想熱鍵模仿Visual Studio的「兩步走快捷方式」的行爲 - 即按Ctrl鍵 - ķ將使「微距模式」;在微距模式下,按某些鍵將運行一個宏,然後禁用「微距模式」,其他任何鍵都將禁用微距模式。如何使用Autoit/Autohotkey模仿Visual Studio的「Ctrl-K,C」兩步宏行爲?

示例 - 輸入一個文件名時,我希望能夠通過點擊Ctrl鍵插入今天的日期 - ķ,然後按d

有沒有人有一個有狀態的AutoHotkey腳本的行爲像這樣的很好的例子?

回答

8

這AutoHotkey的腳本,當您按下CTRL +ķ,會等你按一個鍵,如果按下d,它會輸入當前日期。

^k:: 
Input Key, L1 
FormatTime, Time, , yyyy-MM-dd 
if Key = d 
    Send %Time% 
return 
5

接受的答案略有變化 - 這是我最終使用的。我正在捕獲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