Using the Program

AutoHotkey doesn't do anything on its own; it needs a script to tell it what to do. A script is simply a plain text file with the .ahk filename extension containing instructions for the program, like a configuration file, but much more powerful. A script can do as little as performing a single action and then exiting, but most scripts define a number of hotkeys, with each hotkey followed by one or more actions to take when the hotkey is pressed.

#z::Run https://www.autohotkey.com  ; Win+Z

^!n::  ; Ctrl+Alt+N
if WinExist("Untitled - Notepad")
    WinActivate
else
    Run Notepad
return

Tip: If your browser supports it, you can download any code block (such as the one above) as a script file by clicking the button which appears in the top-right of the code block when you hover your mouse over it.

목차

Create a Script

There are a couple of common ways to create a script file:

See Scripting Language for details about how to write a script.

Edit a Script

To open a script for editing, right-click on the script file and select Edit Script. If the script is already running, you can use the Edit command or right-click the script's tray icon and select Edit This Script. By default this will open Notepad, but that can be changed by writing to the registry as shown here. Of course, you can always open your text editor first and then open the script as you would any other text file.

After editing a script, you must run or reload the script for the changes to take effect. A running script can usually be reloaded via its tray menu.

Run a Script

With AutoHotkey installed, there are several ways to run a script:

Most scripts have an effect only while they are running. Use the tray menu or the ExitApp command to exit a script. Scripts are also forced to exit when Windows shuts down. To configure a script to start automatically after the user logs in, the easiest way is to place a shortcut to the script file in the Startup folder.

Scripts can also be compiled; that is, combined together with an AutoHotkey binary file to form a self-contained executable (.exe) file.

Tray Icon

By default, each script adds its own icon to the taskbar notification area (commonly known as the tray).

The tray icon usually looks like this (but the color or letter changes when the script is paused or suspended): H

Right-click the tray icon to show the tray menu, which has the following options by default:

By default, double-clicking the tray icon shows the script's main window.

The Menu command can be used to customise the tray icon and menu.

The #NoTrayIcon directive can be used to hide the tray icon.

Main Window

The script's main window is usually hidden, but can be shown via the tray icon or one of the commands listed below to gain access to information useful for debugging the script. Items under the View menu control what the main window displays:

Known issue: Keyboard shortcuts for menu items do not work while the script is displaying a message box or other dialog.

The built-in variable A_ScriptHwnd contains the unique ID (HWND) of the script's main window.

Closing this window with WinClose (even from another script) causes the script to exit, but most other methods just hide the window and leave the script running.

Minimizing the main window causes it to automatically be hidden. This is done to prevent any owned windows (such as GUI windows or certain dialog windows) from automatically being minimized, but also has the effect of hiding the main window's taskbar button. To instead allow the main window to be minimized normally, override the default handling with OnMessage. 예를 들어:

; This prevents the main window from hiding on minimize:
OnMessage(0x0112, Func("PreventAutoMinimize")) ; WM_SYSCOMMAND = 0x0112
OnMessage(0x0005, Func("PreventAutoMinimize")) ; WM_SIZE = 0x0005
; This prevents owned GUI windows (but not dialogs) from automatically minimizing:
OnMessage(0x0018, Func("PreventAutoMinimize"))

PreventAutoMinimize(wParam, lParam, uMsg, hwnd) {
    if (uMsg = 0x0112 && wParam = 0xF020 && hwnd = A_ScriptHwnd) { ; SC_MINIMIZE = 0xF020
        WinMinimize
        return 0 ; Prevent main window from hiding.
    }
    if (uMsg = 0x0005 && wParam = 1 && hwnd = A_ScriptHwnd) ; SIZE_MINIMIZED = 1
        return 0 ; Prevent main window from hiding.
    if (uMsg = 0x0018 && lParam = 1) ; SW_PARENTCLOSING = 1
        return 0 ; Prevent owned window from minimizing.
}

Main Window Title

The title of the script's main window is used by the #SingleInstance and Reload mechanisms to identify other instances of the same script. Changing the title prevents the script from being identified as such. The default title depends on how the script was loaded:

Loaded FromTitle Expression예제
.ahk fileA_ScriptFullPath " - AutoHotkey v" A_AhkVersionE:\My Script.ahk - AutoHotkey v1.1.33.09
Main resource (compiled script)A_ScriptFullPathE:\My Script.exe
Any other resourceA_ScriptFullPath " - " A_LineFileE:\My AutoHotkey.exe - *BUILTIN-TOOL.AHK

The following code illustrates how the default title could be determined by the script itself (but the actual title can be retrieved with WinGetTitle):

title := A_ScriptFullPath
if !A_IsCompiled
    title .= " - AutoHotkey v" A_AhkVersion
; For the correct result, this must be evaluated by the resource being executed,
; not an #include (unless the #include was merged into the script by Ahk2Exe):
else if SubStr(A_LineFile, 1, 1) = "*" && A_LineFile != "*#1"
    title .= " - " A_LineFile

Embedded Scripts [v1.1.34+]

Scripts may be embedded into a standard AutoHotkey .exe file by adding them as Win32 (RCDATA) resources using the Ahk2Exe compiler. To add additional scripts, see the AddResource compiler directive.

An embedded script can be specified on the command line or with #Include by writing an asterisk (*) followed by the resource name. For an integer ID, the resource name must be a hash sign (#) followed by a decimal number.

The program may automatically load script code from the following resources, if present in the file:

IDSpec사용법
1*#1 This is the means by which a compiled script is created from an .exe file. This script is executed automatically and most command line switches are passed to the script instead of being interpreted by the program. External scripts and alternative embedded scripts can be executed by using the /script switch.
2*#2 If present, this script is automatically "included" before any script that the program loads, and before any file specified with /include.

When the source of the main script is an embedded resource, the program acts in "compiled script" mode, with the exception that A_AhkPath always contains the path of the current executable file (the same as A_ScriptFullPath). For resources other than *#1, the resource specifier is included in the main window's title to support #SingleInstance and Reload.

When referenced from code that came from an embedded resource, A_LineFile contains an asterisk (*) followed by the resource name.

Command Line Usage

See Passing Command Line Parameters to a Script for command line usage, including a list of command line switches which affect the program's behavior.

AutoHotkey.exe의 호환성

AutoHotkey.exe 파일만 있으면 어떤 .ahk 스크립트도 실행할 수 있습니다.

[AHK_L 51+]: AutoHotkey.exe 이름을 바꾸면 기본값으로 실행되는 스크립트의 이름도 바뀝니다. 오토핫키를 설치하지 않고 컴퓨터에 사용하기 위해 스크립트를 컴파일하는 방법의 대안이 될 수 있습니다. 예를 들면, MyScript.exe는 파일이름이 주어지지 않으면 자동으로 MyScript.ahk를 실행합니다. 그러나 다른 스크립트도 역시 실행할 수 있습니다.

설치 옵션

조용하게 오토핫키는 기본 디렉토리에 설치하려면 (유/소음 모드에서 보여주는 디렉토리), 매개변수 /S를 설치기에 건네면 됩니다. 예를 들어:

AutoHotkey_1.1.34.03_setup.exe /S

기본 디렉토리 말고 다른 디렉토리에 설치하려면 /D 매개변수로 지정합니다 ( /S가 없을 경우, 설치기가 보여주는 기본 디렉토리가 변경됩니다). 예를 들어:

AutoHotkey_1.1.34.03_setup.exe /S /D=C:\Program Files\AutoHotkey

Version: 오토핫키가 벌써 설치되어 있다면, 자동으로 어느 버전의 AutoHotkey.exe인지 탐지하여 기본값으로 설정합니다. 그렇지 않으면, 기본값은 유니코 32-비트 또는 유니코드 64-비트로서 OS가 64-비트인가 아닌가에 따라 달라집니다. 기본값으로 설정된 AutoHotkey.exe 버전을 오버라이드 하려면, 다음 스위치 중 하나를 건네면 됩니다:

예를 들어, 다음은 조용하게 ANSI 32-비트를 기본값으로 설정하고 설치합니다:

AutoHotkey_1.1.34.03_setup.exe /S /A32

Uninstall: 조용하게 AutoHotkey를 제거하려면, /Uninstall 매개변수를 Installer.ahk에 건넵니다. 예를 들어:

"C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Program Files\AutoHotkey\Installer.ahk" /Uninstall

AutoHotkey가 1.1.08.00 이전 버전이라면, uninst.exe /S를 사용하십시오. 예를 들어:

"C:\Program Files\AutoHotkey\uninst.exe" /S

주의: Installer.ahk는 관리자 권한으로 실행해야 제대로 작동합니다.

Extract [v1.1.09.04+]: A link is present in the bottom-right corner of the installer GUI to extract files without installing, and the /E switch can be used to invoke it from the command line. 예를 들어:

AutoHotkey_1.1.34.03_setup.exe /D=F:\AutoHotkey /E

Restart scripts [v1.1.19.02+]: 조용한 설치/제거 모드에서 스크립트를 실행하면 필요한 경우 자동으로 닫힙니다. /R 스위치를 건네면 실행 중인 EXE를 이용하여 자동으로 이런 스크립트를 재적재할 수 있습니다. 명령어 줄 인자가 필요 없습니다. Setup will attempt to launch the scripts via Explorer, so they do not run as administrator if UAC is enabled.

Taskbar buttons [v1.1.08+]: On Windows 7 and later, taskbar buttons for multiple scripts are automatically grouped together or combined into one button by default. The Separate taskbar buttons option disables this by registering each AutoHotkey executable as a host app (IsHostApp).

[v1.1.24.02+]: For command-line installations, specify /IsHostApp or /IsHostApp=1 to enable the option and /IsHostApp=0 to disable it.

Run with UI Access [v1.1.24.02+]

The installer GUI has an option "Add 'Run with UI Access' to context menus". This context menu option provides a workaround for common UAC-related issues by allowing the script to automate administrative programs - without the script running as admin. To achieve this, the installer does the following:

If any these UIA files are present before installation, the installer will automatically update them even if the UI Access option is not enabled.

For command-line installations, specify /uiAccess or /uiAccess=1 to enable the option and /uiAccess=0 to disable it. By default, the installer will enable the option if UAC is enabled and the UI Access context menu option was present before installation.

Scripts which need to run other scripts with UI access can simply Run the appropriate UIA.exe file with the normal command line parameters.

알려진 한계:

For more details, see Enable interaction with administrative programs on the archive forum.