Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I mimic Visual Studio's "Ctrl-K, C" two-step macro behaviour using Autoit / Autohotkey?

Tags:

autohotkey

I'm trying to set up AutoHotkey macros for some common tasks, and I want the hotkeys to mimic Visual Studio's "two-step shortcut" behaviour - i.e. pressing Ctrl-K will enable "macro mode"; within macro mode, pressing certain keys will run a macro and then disable 'macro mode', and any other key will just disable macro mode.

Example - when typing a filename, I want to be able to insert today's date by tapping Ctrl-K, then pressing D.

Does anyone have a good example of a stateful AutoHotkey script that behaves like this?

like image 564
Dylan Beattie Avatar asked Oct 14 '08 10:10

Dylan Beattie


2 Answers

This Autohotkey script, when you press ctrl+k, will wait for you to press a key and if you press d, it will input the current date.

^k::
Input Key, L1
FormatTime, Time, , yyyy-MM-dd
if Key = d
    Send %Time%
return
like image 126
Andres Avatar answered Dec 01 '22 01:12

Andres


A slight variation on the accepted answer - this is what I've ended up using. I'm capturing Ctrl+LWin (left Windows key) so it doesn't conflict with VS inbuilt Ctrl-K shortcuts.

; 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
like image 32
Dylan Beattie Avatar answered Dec 01 '22 00:12

Dylan Beattie