6 Answers
Use Autohotkey. The scripting language is non standard and can be difficult to learn, but if all you’re wanting to do is reliably launch programs, its simple. Plus you can base shortcuts off the Windows key! Use following sample script and modify it to your needs. (Lines starting with ;
are comments.)
;win + alt + e ... unload ipod
#!E::
run d:\Downloads\Apps\deveject\eject ipod.bat
return
;win + w ... launch winamp
#w::
run c:\program files (x86)\winamp\winamp.exe
return
;win + a ... launch AS400
#a::
run C:\Program Files (x86)\IBM\Client Access\Emulator\Private\1.ws
return
;win + Shift a ... launch AS400 Printer
#+a::
run C:\Program Files (x86)\IBM\Client Access\Emulator\Private\3.ws
return
;win + ctrl + Shift a ... launch 2nd AS400
#^+a::
run C:\Program Files (x86)\IBM\Client Access\Emulator\Private\2.ws
return
Save this as a .ahk file on your desktop, install autohotkey and run it.
Every time you press any key combination, AutoHotkey will scan this script. If it matches any of the key combinations that preceed a ::
, it will execute the next command. If the return statement is missing, the AHK will continue to scan the script for matches after executing your statement. The key combinations are described below.
# = Windows Key
+ = Shift
^ = Control
! = Alt
You can use these in any combination with the letters of your keyboard. One combination I find extremely useful is as follows.
; ALT Backtick ... ctrl f4
!`::
Loop, parse, RcvCtrlW, `,
{
IfWinActive %A_LoopField%
{
sendinput ^w
Return
}
}
sendinput ^{f4}
return
; win Backtick ... alt f4
#`::
sendinput !{f4}
return
This is Alt + ` and Win + `. When this script is running and I press alt + `, the script sends ctrl + F4. Win + ` becomes alt + F4.
Autohotkey is basically its own programming language. I have scripts set up that simulate “Rocker Gestures” system wide. I have GMail like shortcuts for my email. If you spend the time to learn some of its tricks, you can get nuts with it. Lifehacker has a whole bunch of useful scripts for Autohotkey. Have Fun!
1
Here’s how I use AutoHotKey in a manner that meets your idempotent requirement.
As an example, I’ve hooked Caps Lock
+a
to a Firefox window on Stack Overflow, Caps Lock
+s
to Firefox at Super User, and Caps Lock
+d
to a command prompt.
StartOrToggleMinimize(TheWindowTitle,TheAppPath)
{
SetTitleMatchMode, 2
DetectHiddenWindows, Off
IfWinActive, %TheWindowTitle%
{
WinMinimize, %TheWindowTitle%
}
else
{
IfWinExist, %TheWindowTitle%
{
WinGet, winid, ID, %TheWindowTitle%
DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
}
else
{
run %TheAppPath%
}
}
return
}
; the actual hotkeys:
CapsLock & a::StartOrToggleMinimize("Stack Overflow", "c:\program files\mozilla firefox\firefox.exe -new-window stackoverflow.com")
CapsLock & s::StartOrToggleMinimize("Super User", "c:\program files\mozilla firefox\firefox.exe -new-window superuser.com")
CapsLock & d::StartOrToggleMinimize("cmd", "cmd")
You can change the title match mode to be as restrictive as you need. If I had another hotkey that matched on “Mozilla Firefox” (instead of “Super User”, for example) it would cycle through all my Firefox instances, since each has that text in the window title and I have it set to match the text anywhere in the title.
This script is heavily based on this article at LifeHacker.
4
Yet another alternative to launch your programs fast and intuitively:
Launchy is a free windows and linux utility designed to help you forget about your start menu, the icons on your desktop, and even your file manager.
Launchy indexes the programs in your start menu and can launch your documents, project files, folders, and bookmarks with just a few keystrokes!
2
Unfortunately 6 years later with Windows 10 the same issues exist, and with a recent Windows 10 update I found that some shortcuts/programs are no longer
idempotent! Especially Putty where I have multiple shortcuts for the same session.
So I use AutoHotKey and modified the function shared in this thread (based on this article at LifeHacker) so that it uses an INI file to keep track of each shortcut. This does not use the Windows Title of each program as that can change in Putty if you use screen or SSH into another server, a feature I personally want to keep!
Also included is a function “DeleteINIEntry()” which you can create a shortcut for to have it remove an UniqueName entry from the INI file. Or you can just manually edit and change the file.
INIFilePath := "C:\Temp\AHK.ini"
RunOrSwitchWin( UniqueName, AppPath )
{
global INIFilePath
IniRead, TargetID, %INIFilePath%, windowids, %UniqueName%
ActiveID := WinExist("A")
; cannot use '=' here as comparing an integar to string doesn't work well
IfEqual TargetID, %ActiveID%
{
WinMinimize
return
}
WinGet, AllIDs, list
Loop, %AllIDs%
{
this_id := AllIDs%A_Index%
ifEqual TargetID, %this_id%
{
DllCall("SwitchToThisWindow", "UInt", this_id, "UInt", 1)
return
}
}
run, %AppPath%,,, CurrentPID
WinWait ahk_pid %CurrentPID%
IniWrite, % WinExist("A"), %INIFilePath%, windowids, %UniqueName%
return
}
DeleteINIEntry()
{
global INIFilePath
InputBox, UniqueName, Delete INI Entry, Enter UniqueName
If ErrorLevel = 0
IniDelete, %INIFilePath%, windowids, %UniqueName%
return
}
^!3::DeleteINIEntry()
; Putty shortcuts.
; ^!1 is NOT idempotent and will run it over and over again.
^!1::run "C:\Program Files\PuTTY\putty.exe"
^!2::RunOrSwitchWin( "session1", "C:\Program Files\PuTTY\putty.exe -load session1" )
If you don’t want the window to Minimize then simply comment out (prepend a 😉 to the WinMinimize line and it will just stay focused on the active window.
It is not unrelated activity, explorer is the process that handles these shortcuts.
There are utilities (e.g. http://www.vsisystems.com/keyboardshortcuts.htm) that purport to have this functionality, but I don’t know if any of them would solve the speed issue.
If Explorer is busy then it can’t handle the shortcuts, so another program is required.
A simple and efficient launcher is PS Hot Launch VVL:
This is a free utility that allows you
to define your own hotkeys so that a
single key press can launch an
application, insert commonly used
text, change your audio volume, or
just about anything else. The program
requires Win95/98/ME or WinNT/2000/XP,
and is an excellent performer even on
slow machines. PS Hot Launch is the
perfect alternative to the Start menu
and the Quick Launch panel.
9