Windows automation with AutoHotkey

Desktop automation pays off wherever a task is predictable: the same windows, the same fields, the same order. AutoHotkey is a good fit for that middle ground where a full integration is overkill but doing it by hand is wasting an hour a week.

Choosing what to automate first

  1. Write down a task you repeat at least daily.
  2. Note every keystroke and click it takes.
  3. Look for the steps that never vary — those are the ones to script.
  4. Leave decisions to yourself; let the script handle the mechanical part.

Window management

#Requires AutoHotkey v2.0

#o::
{
    Run "outlook.exe"
    WinWait "ahk_exe outlook.exe", , 10
    WinActivate "ahk_exe outlook.exe"
    WinMove 0, 0, A_ScreenWidth, A_ScreenHeight
}

Identify windows by process with ahk_exe rather than by title. Titles change with the open document; process names do not.

Driving an application

Keyboard paths beat pixel coordinates. A menu reached with Send "!f{Down 3}{Enter}" keeps working after a window is resized, while a click at 640,480 does not. When a step is slow, wait for evidence that it finished — WinWaitActive, ClipWait or a check with WinExist — instead of guessing with a long Sleep.

File and folder chores

#n::
{
    folder := A_Desktop "\" FormatTime(A_Now, "yyyy-MM-dd")
    DirCreate folder
    Run "explorer.exe " folder
}

Jobs that run without you

SetTimer covers anything from a reminder to a periodic backup copy. For work that must happen when you are not logged in, hand the job to Task Scheduler and let it launch the script.

Making automation reliable

Ready-made building blocks are on the scripts and examples pages; the reference material sits under commands.

Frequently asked questions

How do I automate repetitive tasks on Windows?

Script the steps that never vary with AutoHotkey: activate the window, send the keystrokes, and wait for each step to complete before the next.

Should I automate with mouse clicks or keystrokes?

Keystrokes. They keep working when a window moves or resizes, while fixed click coordinates break.

Can a script run on a schedule?

Yes. Use SetTimer inside a running script, or have Task Scheduler launch the script at set times.


AutoHotkeyTools.com is an Windows resource covering AutoHotkey tools, scripts, hotkeys, tutorials and desktop automation. It is .