Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to run a certain batch when I hit some given combination of keys.

It's as simple as, when I hit, say, CTRL+D, I want to execute the command C:\scripts\run.

Is there any way to do this, perhaps with some third party software?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

You want http://www.autohotkey.com

It has the ability to map arbitrary keystrokes to files or programs. Lots of examples, including ones very similar to what you're trying to do, in their quick start tutorial: http://www.autohotkey.com/docs/Tutorial.htm

share|improve this answer
    
Worked beautifully. Thanks so much. –  Jeremy Apr 30 '12 at 2:11
1  
Another suitable option (and the project that autohotkey was built off of) is AutoIt. –  MaQleod Apr 30 '12 at 2:15

To expand on @ckhan's answer, You can write an AutoHotkey script that uses hotkeys and the Run command. For example,

^x::
    Run, C:\MyScript.bat
    return

will launch C:\MyScript.bat when you press Ctrl+X.


If you don't want to use third party software, Windows offers a similar solution with shortcut (.lnk) files. You can create a shortcut to your script or executable and then define a shortcut key in the Properties dialog for the shortcut. The limitation of this approach is that not all key combinations are accepted. For example, Ctrl+X is replaced with Ctrl+Alt+X.

shortcut key


Note:

For either method, if you want to use commands without first creating a batch file, I recommend using the /c (run and close) or /k (run and keep open) flags of cmd.exe. For example, you could replace C:\MyScript.bat above with

cmd.exe /c "abc"

to run the command abc.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.