My Technical Notes

Wednesday, 12 December 2012

Visual Studio Style Chords in Autohotkey

I found the following script on stackprinter.com, and it is an example of what the Input command can accomplish.

There are at least two scenarios in which we could use chords:

  • we cannot use hotstrings because it would interfere with the program.
  • we want to group related hotkeys to simplify their use.

In the example below, pressing Ctrl-` (found near the ESCAPE key) will require a further two characters. cp will make it open the command prompt, ca will make it run the calculator app, and ou will make it open Outlook.


^`::

Input, TextEntry1, L1,{Esc}{Enter}{F1}{Down}{Up}
endKey=%ErrorLevel%

Input, TextEntry2, L1 T1,{Esc}{Enter}

timeout=%ErrorLevel%

entry=%TextEntry1%%TextEntry2%

if entry=cp
{
    ; Command prompt
    run cmd
}
else if entry=ca
{
    ; Calculator
    run calc
}
else if entry=ou
{
 ; Outlook
 SetTitleMatchMode 2

 IfWinExist, Microsoft Outlook
 {
  WinActivate
 }
 else
 { 
  run outlook
 }

 SetTitleMatchMode 1
}
return

1 comment:

Ben Northway said...

Thanks! This is really cool