AutoHotkey: Switch or Launch App

By Xah Lee. Date: . Last updated: .

This page shows you how to set a key to switch to your favorite app. For example, set F8 to switch to browser. This is covers Microsoft Windows. For Mac or Linux, see How to Set Key to Switch to Browser

There are 3 or 4 apps you use all the time. It's efficient to set a single key to switch to them, such as F5 F6 F7 F8. This way, you have muscle memory, and also, no use pinky to press Alt+Tab, and no need to glance at the screen to decide if you need to press Tab again.

There are many ways to setup one single key to switch/launch a app. We'll cover the most easy, fast, way first.

Use Windows Builtin Launch/Switch Mechanism

This is the fastest and most reliable method.

Pin the apps you want to the taskbar, then, ❖ Window+1 will launch or switch the left most one. ❖ Window+2 for the second one, etc.

For detail, see Windows: Key to Launch or Switch App

Or, you can use AutoHotkey with this script:

; make F1 send Win+1
$F1::Send #1

; make F2 send Win+2
$F2::Send #2

[see AutoHotkey Tutorial]

Use AutoHotkey to Launch/Switch App

Suppose you want a hotkey that launches a browser, but if it is already running, just switch to it.

Launch/Switch Firefox

; launch or switch to Firefox
; Version 2021-02-21 2022-01-19
if WinExist("ahk_class MozillaWindowClass")
WinActivateBottom, ahk_class MozillaWindowClass
 Run "C:\Program Files\Mozilla Firefox\firefox.exe"

; shift+f8

If you don't know what to do with this, see AutoHotkey Tutorial

Launch/Switch Emacs

For different app, you need to use different code. Here's a emacs example.

; launchOrSwitchEmacs
; version 2021-02-21 2022-01-19
if WinExist("ahk_class Emacs")
  WinActivate, ahk_class Emacs
  Run "%HOMEPATH%\Downloads\emacs-27.1-x86_64\bin\runemacs"


How to find window name or app name?

To find out what is the window's ahk_class , right click on the AHK icon and chose Window Spy , then click on a window you want.

win 10 AutoHotkey window spy 2021-02-14 QftPt
AutoHotkey Window Spy 2021-02-14
win 10 AutoHotkey window spy 2021-02-14
AutoHotkey Window Spy window

AutoHotkey Tutorial

AutoHotkey logo nz9fX