The Computer Oracle

Run a CMD comand from a key stroke?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Thinking It Over

--

Chapters
00:00 Run A Cmd Comand From A Key Stroke?
00:24 Accepted Answer Score 9
00:43 Answer 2 Score 15
01:50 Answer 3 Score 0
02:06 Thank you

--

Full question
https://superuser.com/questions/418533/r...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #commandline #batch

#avk47



ANSWER 1

Score 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.




ACCEPTED ANSWER

Score 9


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




ANSWER 3

Score 0


Unfortunately this seems to depend on the OS. In Linux Debian 12, in the main menu under 'Keyboard Shortcuts' there is the predefined key combination for 'Run a terminal' as Ctrl+Alt+T.