What an AHK file is and why you'd save one

An AHK file is a plain text file that contains instructions written in the AutoHotkey language. AutoHotkey is a free program that lets you automate repetitive tasks on Windows — things like remapping keyboard keys, creating keyboard shortcuts that run programs, or making your mouse do multiple actions with one click. When you write those instructions and save them as an AHK file, AutoHotkey can read and run them.

You save something as an AHK file when you've written automation code and want to keep it in a format that AutoHotkey recognizes. The file extension .ahk tells Windows and AutoHotkey that this is an AutoHotkey script, not just any text file.

Key Takeaways

  • An AHK file is a text file containing AutoHotkey code, saved with the .ahk extension so AutoHotkey can run it.
  • You can save an AHK file from Notepad, VS Code, or any plain text editor by typing your code and choosing "Save As" with the filename ending in .ahk.
  • The file type must be set to "All Files" or "Plain Text" in the save dialog, not "Text Document" or "Word Document".
  • Once saved, you can run the AHK file by double-clicking it if AutoHotkey is installed, or by right-clicking and selecting "Run with AutoHotkey".

Saving an AHK file from Notepad

Notepad is the simplest tool for writing and saving AHK files because it creates plain text with no hidden formatting. Open Notepad (search for "Notepad" in the Windows Start menu), then type or paste your AutoHotkey code into the blank window.

Once your code is in Notepad, go to File at the top left, then click Save As. A dialog box will open. In the filename field at the bottom, type a name for your script followed by .ahk — for example, my-shortcuts.ahk or mouse-automation.ahk. Before you click Save, look for the "Save as type" dropdown (usually near the filename field) and change it from "Text Documents (*.txt)" to All Files (*.*). This tells Notepad to save the file with the .ahk extension you typed, not to add .txt automatically. Then click Save.

Saving an AHK file from VS Code or another editor

If you use VS Code, Sublime Text, or another code editor, the process is similar but slightly faster. Type or paste your AutoHotkey code, then go to File and click Save As. In the filename field, type your script name with the .ahk extension — for example, keyboard-remap.ahk.

Most code editors are smart enough to recognize the .ahk extension and save it correctly without changing the file type. However, if you see a dropdown asking what language the file is, look for AutoHotkey in the list and select it. If AutoHotkey is not listed, you can still save it as plain text — the .ahk extension is what matters to AutoHotkey itself.

Why the file type matters

The most common mistake when saving an AHK file is accidentally saving it as a .txt file instead. This happens when you use "Save As" but forget to change the file type dropdown from "Text Documents" to "All Files". If you do this, Windows will add .txt to the end of your filename automatically, creating a file named something like my-script.ahk.txt. AutoHotkey won't recognize this as a script file.

To check what you've saved, open File Explorer, navigate to the folder where you saved the file, and look at the full filename. If it ends in .ahk.txt, you need to rename it. Right-click the file, select Rename, and delete the .txt part so it ends only in .ahk. Then press Enter.

Running your AHK file once it's saved

After you've saved your file as .ahk, you need AutoHotkey installed on your computer for it to run. If you don't have it yet, read it free from the official AutoHotkey website (autohotkey.com). Install it using the default settings.

Once AutoHotkey is installed, you can run your AHK file by double-clicking it in File Explorer. A small icon will appear in your system tray (the area at the bottom right of your screen), and your automation will be active. To stop it, right-click that icon and select Exit. You can also right-click an AHK file and select Run with AutoHotkey if double-clicking doesn't work.

Editing an AHK file after you've saved it

If you need to change your script later, right-click the AHK file in File Explorer and select Edit Script (if AutoHotkey is installed) or Open with and choose Notepad or your editor. Make your changes, then save the file the same way you did before — File > Save (not Save As). The file will stay as an AHK file.

If you're running the script when you edit it, you'll need to stop it and run it again for the changes to take effect. Right-click the AutoHotkey icon in your system tray and select Exit, then double-click the AHK file again to restart it with your new code.

Organizing and storing your AHK files

As you create more scripts, it's helpful to keep them in one folder. Create a folder called something like AutoHotkey Scripts on your Desktop or in your Documents folder, and save all your AHK files there. This makes them straightforward to find and run.

You can also create a shortcut to an AHK file on your Desktop for quick access. Right-click the AHK file in File Explorer, select Create shortcut, and move the shortcut to your Desktop. Double-clicking the shortcut will run the script just like double-clicking the file itself.

Frequently Asked Questions

What's the difference between saving as AHK and saving as TXT?

A TXT file is plain text with no special meaning to any program. An AHK file is also plain text, but the .ahk extension tells AutoHotkey that this file contains code it should run. Windows and AutoHotkey treat them differently based on the extension alone.

Can I save an AHK file from Word or Google Docs?

You can, but it's not recommended. Word and Google Docs add hidden formatting that can break AutoHotkey code. Always use a plain text editor like Notepad, VS Code, or Sublime Text. If you must copy code from Word, paste it into Notepad first, then save it as AHK.

What happens if I save an AHK file with the wrong extension?

AutoHotkey won't recognize it as a script. You can rename the file in File Explorer by right-clicking it, selecting Rename, and changing the extension to .ahk. The code inside stays the same — only the filename changes.

Do I need to install anything before saving an AHK file?

No. You can write and save AHK files in any text editor without AutoHotkey installed. You only need AutoHotkey installed if you want to actually run the script and use the automation it contains.

Can I save an AHK file on a Mac or Linux computer?

You can save the file, but AutoHotkey only runs on Windows. If you save an AHK file on a Mac or Linux machine, you won't be able to run it there. You'd need to transfer it to a Windows computer to use it.