What Is an AHK File?

AutoHotkey executes AHK scripts, and a text editor can edit one

What to Know

  • An AHK file is an AutoHotkey script.
  • Open one with AutoHotkey, or edit it with a text editor.
  • Convert one to EXE with Ahk2Exe.

This article explains what an AHK file is and how to open one on your computer, plus how to convert one to a more widely used executable format (EXE).

What Is an AHK File?

A file with the .AHK file extension is an AutoHotkey script. It's a plain text file that's used by a free scripting tool for automating tasks in Windows.

AutoHotkey uses this file to automate things like clicking window prompts, typing, and lots more. It's especially helpful for long, drawn out, and repetitive actions that always follow the exact same steps.

AHK files in Windows 10

How to Open an AHK File

Even though AHK files are just made up of readable text, they're only understood and executed within the context of the free AutoHotkey program. It has to be installed on the same computer the file is executed from in order for its tasks to be performed.

So long as the syntax is correct, the software understands what's written in the file as a series of commands that AutoHotkey should follow.

Take extra care to only use executable files like these that you've made yourself or that you've downloaded from a trusted source. The moment an AHK file exists on a computer that has AutoHotkey installed is the moment you put your computer at risk. The file might contain harmful scripts that could secretly do lots of damage to both your personal files and to important system files.

All that said, because AHK files are written in plain text, any text editor (like Notepad in Windows or one from our Best Free Text Editors list) can be used to build the steps and make changes to existing files. Again, though, AutoHotkey must be installed to make the commands included in the text file actually do something.

This means if you make one of these files on your computer, and it works fine with AutoHotkey installed, you can't send that same file to someone else who doesn't have the software installed and expect it to work for them, too. That is, unless you convert it to EXE, which you can learn more about in the section below.

It may not seem like you've opened an AHK file if the instructions inside the file don't do something obvious. For example, if yours is set up to just type out a sentence after you've entered a special combination of keyboard commands, then opening that specific file won't reveal any window or indication that it's running. However, you'll for sure know you've opened one if it's configured to open other programs, shut down your computer, etc.—something obvious.

However, all open scripts are shown in Task Manager, as well as in the notification area of the Windows taskbar. So if you're not sure whether one is actively running in the background, be sure to check those areas.

How to Convert an AHK File

AHK files can be converted to EXE so they can run without having to explicitly install AutoHotkey. You can read more about converting to EXE on the company's Convert a Script to an EXE (ahk2exe) page.

Basically, the quickest way to do that is to right-click the file and choose Compile Script. You can also do this conversion through the Ahk2Exe program included in AutoHotkey's installation folder. You can search for it through the Start menu or look in this folder:

C:\Program Files\AutoHotkey\Compiler

AutoIt is a similar program, but it uses the AUT and AU3 file formats instead. There might not be an easy way to convert AHK to one of those formats, so you might have to completely rewrite the script in AutoIt if this is what you're after.

AHK Script Examples

Below are a few examples of AutoHotkey scripts. Just copy one into a text editor, save it with the .AHK file extension, and then open it on a computer that's running AutoHotkey. They'll run in the background (you won't "see" them open) and work instantly when the corresponding keys are triggered.

This one will show or hide hidden files each time the Windows and H keys are pressed at the same time. This is much quicker than manually showing/hiding hidden files.

; Show or hide hidden files
#h:: 
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden 
If HiddenFiles_Status = 2 
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1 
Else 
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2 
WinGetClass, eh_Class,A 
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA") 
send, {F5} 
Else PostMessage, 0x111, 28931,,, A 
Return

The following is a much simpler script that's completely editable to your liking. It will open a program with a quick keyboard shortcut. In this example, we've set it to open Notepad when WIN+N is pressed.

#n::Run Notepad

Here's a similar one that launches Command Prompt from anywhere:

#p::Run cmd

This is another one we like that uses 7-Zip to automatically unzip an archive if you hold down Ctrl+Alt while you click once on the file:

!^LButton::
temp = %clipboard%
KeyWait, LButton, D
send {LButton}
sleep,100
Send, {Ctrl Down}c{Ctrl Up}
file = %clipboard% ;get file address
clipboard = %temp% ;restore clipboard
outdir := getdir(file)
if (A_Is64bitOS = 1)
{
runwait, "C:\Program Files\7-Zip\7z.exe" x "%file%" -o"%outdir%" -y,,hide
}
else
{
runwait, "C:\Program Files (x86)\7-Zip\7z.exe" x "%file%" -o"%outdir%" -y,,hide
}
return
getdir(input)
{
SplitPath, input,,parentdir,,filenoext
final = %parentdir%\%filenoext%
return final
}

See the AutoHotkey Quick Reference for syntax questions, and AutoHotkey Script Showcase for more script examples.

Still Can't Open It?

If your file doesn't run when AutoHotkey is installed, and especially if it doesn't show you text commands when viewed with a text editor, then there's a good chance you don't actually have one of these scripts.

Some files use a suffix at the end that's spelled a lot like "AHK," but that doesn't mean you should treat the files as equals—they don't always open with the same programs or convert with the same tools.

For example, maybe you really have an AHX file, which is a WinAHX Tracker module that has no relation to script files used with AutoHotkey. Or it could be an AHS file used with Photoshop.

Another similar-sounding but totally different file extension is APK. These are applications that run on the Android operating system and are as far from text files as possible, so if you have one of those, you won't be able to use the AutoHotkey openers from above to use it.

ASHX files are another example. Only one letter is added to that file extension, but the format has to do with ASP.NET web server applications instead.

The point here is to research the file extension your file is using so you can find the appropriate program that can open or convert it.

Was this page helpful?