4. Windows Keyboard Shortcut - adolan5/myCMD GitHub Wiki

Creating a Keyboard Shortcut for myCMD with a Windows Shortcut

After having trouble downloading AutoHotKey during one of its typical periods of being flagged as malware by web browsers, I decided to put some more thought into how to create a keyboard shortcut for myCMD. In short, I've managed to do it without any third party libraries, and have the same functionality as the AutoHotKey version.

How it's Done

myCMD.lnk

Hopefully you have already created a shortcut (.lnk file) for myCMD.
There are some cool things you can do with this shortcut. If you look at it's "properties," you'll see that you can set colors, text sizes, opacity, etc. Then, as long as you launch myCMD from that shortcut, those settings will be used. Pretty cool!

The First Solution

A quick way to get a keyboard shortcut going is to first place your newly created .lnk file in the start menu programs directory, which is usually:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs

After putting it in there, you'll notice that myCMD now shows up in your start menu's application list!
Now, look at the properties dialogue for the shortcut. You'll see that there is a "Shortcut Key" field. Set it to your favorite shortcut (mine is ctrl + alt + t), hit ok, and you're done!

  • Note that the shortcut file itself must be in the start menu programs directory (or the Desktop) for this method to work.

One thing that you'll notice, however, is that invoking your new shortcut will only spawn a single instance of myCMD. That's because the shortcut is mapped to one instance of your shortcut. See the second solution for a fuller solution.

The Second Solution

This solution requires the first solution as a prerequisite. The difference here is that, instead of your shortcut file invoking cmd.exe and reading in myCMD's startup.bat, your shortcut file will instead spawn a new instance of myCMD from another shortcut.
To do this:

  • First create a shortcut for myCMD as specified before, and place it somewhere like C:\Tools.
    • This is the shortcut whose properties you'll want to edit for color changes, etc. It is the "actual" myCMD.
  • Next, create another shortcut file, this time with %COMSPEC% /c start <path\to\your\myCMD.lnk> as the target. Essentially, this shortcut launches your other shortcut from a separate terminal window.
    • It is beneficial to name this shortcut file with the same name as the first one you created, so you don't see a console "flash" on your taskbar.
  • Follow the steps in the first solution to place this new shortcut (that calls out to the other shortcut) in the start menu programs directory, and set its shortcut key.
  • As a final, quality-of-life step, look at the properties of the shortcut that is now in the start menu programs directory, and set its "Run" field to "Minimized." This will prevent a console window from appearing to launch a new instance of myCMd.
  • In conclusion:
    • You can now invoke your shortcut key, which will spawn a new instance of cmd.exe, which will immediately launch your myCMD shortcut (which you placed somewhere like C:\Tools\myCMD.lnk).

Advantages

  • No more AutoHotKey!
  • No more configuring something to spin up on boot
  • No more having to restart the AHK script when you change an environment variable like PATH for that updated version to be available in myCMD

Disadvantages

  • Technically opens another terminal to open myCMD. Not ideal, but also not super noticeable.