AutoHotkey Lesson 3: Hotkeys for Apps and Windows

📎 This article includes 1 downloadable practice file ↓

⏱ 1 min read

📘 AutoHotkey Beginner Course · Lesson 3 of 6

In this article
  1. App-specific hotkeys
  2. Switch to or launch
  3. Window control
  4. Where people go wrong
  5. Practice

Some shortcuts only make sense in one app: F1 opening Help in Excel is a common annoyance. #HotIf limits hotkeys to specific windows.

App-specific hotkeys

#HotIf WinActive("ahk_exe EXCEL.EXE")
F1::Send "{F2}"        ; edit cell instead of Help
^+v::Send "^!v"        ; Paste Special
#HotIf                 ; end of the Excel-only block

Find an app’s exe name with Window Spy (right-click the tray icon › Window Spy).

Switch to or launch

#e::{
    if WinExist("ahk_exe EXCEL.EXE")
        WinActivate
    else
        Run "excel.exe"
}
💡 One key per daily app (Excel, Outlook, browser, Tally) replaces endless Alt+Tab cycling.

Window control

WinMove x, y, w, h, "A" moves the active window; WinMaximize, WinMinimize, and WinSetAlwaysOnTop -1, "A" pin a calculator on top.

Where people go wrong

Problem Fix
Hotkey works everywhere Missing #HotIf block
Doesn’t work in admin apps Run the script as administrator too

Practice

Run the script and try the Excel-only keys; change the window size to suit your screen.

📎 Practice files for this article

  • ⌨️
    Lesson 3 script (AutoHotkey v2)Double-click to run after installing AutoHotkey v2.
    ⬇ AHK · 546 B

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong