Bring up the Windows Terminal in a keystroke
I decided to try out the new Windows Terminal to see how it compared to ConEmu, which is my usual console. The recommended way to get the Windows Terminal is to download it from the Microsoft Store so that it can automatically update itself as new versions are released.
While the Windows Terminal is not as mature and feature rich as ConEmu, I did enjoy it, and it’s being actively worked on with plenty of features coming down the road. I’d also recommend following Scott Hanselman’s post about how to make it look nicer.
One feature I missed right away was ConEmu allows you to set a keyboard shortcut to put it in focus. As a software developer, I’m constantly in and out of the terminal, and being able to get to it in a keystroke is very convenient.
Method 1: Pin Windows Terminal to the taskbar
The easiest way to get to the Windows Terminal using a keyboard shortcut is to pin it to the taskbar. Not only does it make it easy to click on with the mouse, but you can also use the Windows Key + [number] keyboard shortcut to launch it or put it in focus.
For example, if on your taskbar from left to right you have: Edge, Chrome, Windows Terminal, then you could use Windows Key + 3 to launch the Windows Terminal, or put it in focus if it’s already open. Similarly, Windows Key + 1 would launch Edge, and Windows Key + 2 would launch Chrome.
This is a simple solution and it works, but the reason I’m not a fan of it is:
- If I reorder the windows on the taskbar then the keyboard shortcut changes.
- This method only works for the first 10 items on the taskbar. i.e. you can’t do Windows Key + 11.
- I find it awkward to use the Windows Key with any numbers greater than 4.
So let’s continue exploring other options.
Method 2: Launch Windows Terminal from the command line
The Windows Terminal is installed as a Microsoft Store app, so the location of the executable isn’t very obvious, and it is likely to change every time the app is updated. This can make launching it via other applications or scripts tough. Luckily, I found this wonderful post describing how to launch Microsoft Store apps from the command line.
From there, I was able to track down that you can launch the Windows Terminal store app using:
explorer.exe shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App
Update: It turns out you can also simply run
wt
from the command line to launch the Windows Terminal, aswt.exe
gets added to the Windows PATH when the Windows Terminal is installed.
Now that we know how to launch it from the command line, you can use this from any custom scripts or application launchers you might use. This is in fact what I show how to do from AutoHotkey further below.
While this command allows us to launch Windows Terminal, it doesn’t allow us to put it in focus if it’s already open, so let’s continue.
Method 3: Launch Windows Terminal via a custom keyboard shortcut
The above post mentions that you can simply navigate to shell:AppsFolder
, find the Windows Terminal app, right-click on it, and choose Create shortcut
.
This will put a shortcut to the application on your desktop, and like any shortcut file in Windows, you can right-click on it, go to Properties
, and assign it a Shortcut key
that can be used to launch the application.
While this will allow you to launch the Windows Terminal with a custom keyboard shortcut, like the previous method, it opens a new instance of the Windows Terminal every time, which isn’t what I want, so let’s continue.
Method 4: Switch to Windows Terminal via keyboard shortcut and AutoHotkey
To use a custom keyboard shortcut to both launch the Windows Terminal, as well as simply switch to the Windows Terminal window if it’s already open, I use AutoHotkey. I’ve blogged about AutoHotkey in the past, and if you’ve never used it you really should check it out.
In a new or existing AutoHotkey script, you can define this function and hotkey:
SwitchToWindowsTerminal()
{
windowHandleId := WinExist("ahk_exe WindowsTerminal.exe")
windowExistsAlready := windowHandleId > 0
; If the Windows Terminal is already open, determine if we should put it in focus or minimize it.
if (windowExistsAlready = true)
{
activeWindowHandleId := WinExist("A")
windowIsAlreadyActive := activeWindowHandleId == windowHandleId
if (windowIsAlreadyActive)
{
; Minimize the window.
WinMinimize, "ahk_id %windowHandleId%"
}
else
{
; Put the window in focus.
WinActivate, "ahk_id %windowHandleId%"
WinShow, "ahk_id %windowHandleId%"
}
}
; Else it's not already open, so launch it.
else
{
Run, wt
}
}
; Hotkey to use Ctrl+Shift+C to launch/restore the Windows Terminal.
^+c::SwitchToWindowsTerminal()
The last line in the script defines the keyboard shortcut and has it call the function.
Here I’m using Ctrl + Shift + C (^+c) for my keyboard shortcut, but you could use something else like Windows Key + C (#c) or Ctrl + Alt + C (^!c). Check out the AutoHotkey key list for other non-obvious key symbols.
You may have also noticed in the code that if the window is already in focus, we minimize it. This allows me to easily switch to and away from the Windows Terminal using the same shortcut keys. Using Alt + Tab would also work to switch back to your previous application.
Finally, the line that actually launches the Windows Terminal is:
Run, wt
If you want the Windows Terminal launched as an elevated command prompt (i.e. as Admin), then you need to add *RunAs
, like this:
Run, *RunAs wt
Also, if you haven’t already, you’ll want to follow these steps to digitally sign your AutoHotkey executable to allow AutoHotkey scripts to be able to interact with applications running as Admin. Without this, the AutoHotkey script will not be able to minimize the Windows Terminal.
Getting the AutoHotkey script running
If you’ve never used AutoHotkey before and want to get this working, all you need to do is:
- Install AutoHotkey
- Create a new text file with a
.ahk
extension - Copy-paste the above script into the file
- Double click the file to run it.
Once that’s done, you should be able to use your keyboard shortcut to switch to Windows Terminal.
You’ll also likely want to have your script startup automatically with Windows so that you don’t have to manually run it all the time.
This is as easy as dropping the .ahk file (or a shortcut to it) in your shell:Startup
directory.
Windows will automatically run all files in this directory every time you log in.
For more detailed instructions and information, see this post
Conclusion
As a software developer, I’m constantly in and out of the terminal for running Git and PowerShell commands. If you’re ok simply pinning Windows Terminal to the taskbar in a dedicated position and don’t mind the preset keyboard shortcut, then roll with that. For myself, using AutoHotkey I can now use Ctrl + Shift + C to switch to and away from the Windows Terminal at anytime, no matter what other application currently has focus, and not having to reach for the mouse.
Shameless Plug: You can also checkout my open source project AHK Command Picker that allows you to use a GUI picker instead of having to remember a ton of keyboard shortcuts.
I hope you’ve found this information helpful.
Happy command lining :)
Comments
Greg
Thank you so much for this post!
I really liked the look of Windows Terminal but couldn’t switch from ConEmu because I depend too much on the ability to focus on it with a keyboard shortcut (essential for a tool which uses a keyboard to control it).
I was about ready to give up and then found this post. I’m looking forward to getting to know Windows Terminal a little better now.
I was going to use the win+n approach, but I thought this is a good chance to try and get AHK baked into my workflow.
Matt
Thank you so much for what you do :)
I found this article and this vlog very useful, I hope you are doing well
Have a nice day :)
Mike
Seems like after an update wt cannot be executed with this script anymore. Trying to find a solution, even from simple cmd wt command is not working.
Spas Zahariev
you are a legend!. This autohotkey script feels so good to use.
Ayon
The terminal seems to launch from the location the script is located in. How to fix this? I’d rather have it start in
%USERPROFILE%.
Marc Brien
Excellent, I did not know about Windows +Num starting the toolbar items. I also love Windows Terminal - Here is a link to using the configuring windows terminal
https://thefuturebymob.medium.com/a082d97426cc
Briain
Fabulously helpful script; thank you! Of course, being a Debian user I used ^t and I’m now a happy chappy :-)
Bidhov
This is great just the 1st one is enough for me.
Alwin
Thank you very much for this script (I’m using method 4), it works fantastically and is exactly what I needed. As you (and others here in the comment section) I used ConEmu and for me the toggle option was the primary reason of using it. ConEmu however often ígnores my AutoHotKey scripts which is beyond annoying. I also very much appreciate that you added the feature to simply switch to the Terminal window if it’s already open. It is really the absolute worst if you want to toggle towards your terminal and you see it minimize. Having it come to focus is crucial for the experience that you’re in control and everything is working fast and smoothly.
For anyone who wants so supercharge their experience and have the terminal appear instantly when toggled (not have its appearance animated): you can turn of these animations in Windows by going to Settings > Ease of access > Display (or simply search for animations in Settings) and turn off ‘Show animations in Windows’. Of course, this will turn them off for the whole system, i.e. all windows will not show any animations when minimized / maximized etc. This is a potential drawback, but in my experience everything will feel more snappy / responsive this way. And actually, there always seem to be one millisecond of an intermediate frame when doing this, so you can see it expand and don’t have to wonder where it went (what happens if there is literally no animation). The animation is simply ‘blazingly fast’ as they say. So, play around with it and do whatever you like.
So again, thank you very much for sharing your script. I’m a very happy user of it now.
Gusti
Here is the script for AHK v2, if anybody needs it:
Jeff Young
Uhhh… Not to be rude. This post seems to be mostly about adding keyboard shortcuts for Windows Terminal, but there are existing keyboard shortcuts in both Windows 10 and Windows 11. [ (Windows + X), i ] will open a user level Windows Terminal. [ (Windows + X), a ] opens the Administrator level Windows Terminal.
There used to be an option in Windows Settings which would allow you to change it between cmd.exe and Powershell. That was in Windows 10 and now that I am in Windows 11, even opening cmd.exe opens it in Windows Terminal.
Once that keyboard shortcut works, you can set up the profiles for powershell, command prompt, or best of all WSL. So if you are doing linux development, you can have it open the terminal for which you are developing. Even if you are not using a local development platform and need SSH, you can set that up to. Simply duplicate your powershell profile, then set the command line for the profile as follows:
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -Command “ssh root@10.0.0.16”
You can either set this as the default start up option, or access it via the down arrow in the taskbar title. I’ve got one setup for my firewall, SAN, and Proxmox Server. You could take this even further and set up Windows terminal to remember what tabs were open on last launch. So it can launch Powershell, Command Prompt, WSL, and SSH. All of them at the same time to all the hosts you need automatically as long as you don’t close the tabs. For this example, I would say to set your “New Instance Behavior” to attach to recently used window, so there are no accidents.
Daniel Schroeder
Thanks for the great info @JeffYoung. Many of those options weren’t available when I originally wrote the article. I appreciate you sharing here 🙂
Leave a Comment
Your email address will not be published. Required fields are marked *