AutoHotkey Lesson 4: Send Keys and Mouse Clicks Safely

📎 This article includes 1 downloadable practice file ↓

⏱ 2 min read

📘 AutoHotkey Beginner Course · Lesson 4 of 6

In this article
  1. Send vs SendText
  2. Pace and wait
  3. Mouse
  4. Where people go wrong
  5. Practice

AHK can type and click for you: filling repetitive forms, moving through rows, entering standard values. Done carelessly, it types into the wrong window. Here’s how to do it safely.

Send vs SendText

Send "{Down}{Enter}" sends keys (braces for special keys; ^ ! + # mean modifiers). SendText "50% off!" types text literally, so symbols aren’t treated as modifiers.

Pace and wait

SetKeyDelay 50                 ; 50 ms between keys
WinWaitActive "ahk_exe EXCEL.EXE",, 5    ; wait up to 5 s for Excel
Sleep 150                      ; small pause for slow apps

Mouse

Click 200, 340 clicks at a position. Set CoordMode "Mouse", "Window" so positions are relative to the window, not the screen, and use Window Spy to read them.

⚠️ Always include an emergency stop such as Esc::ExitApp in any script that sends keys or clicks in a loop. A loop typing into the wrong window can do real damage.
💡 Prefer keyboard navigation (Tab, arrows, shortcuts) over mouse coordinates; it keeps working when windows move or screen resolution changes.

Where people go wrong

Problem Fix
Keys typed into another window WinWaitActive before sending
Missed keystrokes SetKeyDelay / Sleep
Script can’t be stopped Esc::ExitApp

Practice

Open a blank Excel sheet, click A1, run the script and press F8. Press Esc to stop at any time.

📎 Practice files for this article

  • ⌨️
    Lesson 4 script (AutoHotkey v2)Double-click to run after installing AutoHotkey v2.
    ⬇ AHK · 313 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