Waits for the user to type a string (not supported on Windows 9x).

Input [, OutputVar, Options, EndKeys, MatchList]




The name of the variable in which to store the text entered by the user (by default, artificial input is also captured).

If this and the other parameters are omitted, any input in progress in another thread is terminated and its ErrorLevel is set to the word NewInput. By contrast, the ErrorLevel of the current command will be set to 0 if it terminated a prior input, or 1 if there was no prior input to terminate.

Non-character keys such as PageUp and Escape are not stored. Whitespace characters such as TAB are stored literally. ENTER is stored as linefeed (`n) in v1.0.16+ and carriage return (`r) in earlier versions.


A string of zero or more of the following letters (in any order, with optional spaces in between):

B: Backspace is ignored. Normally, pressing backspace during an input will remove the most recently pressed character from the end of the string. Note: If the input text is visible (such as in an editor) and the arrow keys or other means are used to navigate within it, backspace will still remove the last character rather than the one behind the caret (insert position).

C: Case sensitive. Normally, MatchList is not case sensitive.

I: Ignore input generated by AutoHotkey itself, such as the Send command.

L: Length limit (e.g. L5). The maximum allowed length of the input. When the text reaches this length, the input will be terminated and ErrorLevel will be set to the word Max unless the text matches one of the MatchList phrases, in which case ErrorLevel is set to the word Match. If unspecified, the length limit is 16383, which is also the absolute maximum.

M: Modified keystrokes such as Control-A through Control-Z are recognized and transcribed if they correspond to real ASCII characters. Consider this example, which recognizes Control-C:
Transform, CtrlC, Chr, 3 ; Store the character for Ctrl-C in the CtrlC var.
Input, OutputVar, L1 M
if OutputVar = %CtrlC%
     MsgBox, You pressed Control-C.

Note: The characters Ctrl-A through Ctrl-Z correspond to Transform's "Chr 1" through "Chr 26". Also, the M option might cause some keyboard shortcuts such as Ctrl-LeftArrow to misbehave while an Input is in progress.

T: Timeout (e.g. T3). The number of seconds to wait before terminating the input and setting ErrorLevel to the word Timeout. If the input times out, OutputVar will be set to whatever text the user had time to enter. This value can be a floating point number such as 2.5.

V: Visible. Normally, the user's input is hidden from the system (suppressed). Use this option to have the user's keystrokes sent to the active window.

*: Wildcard (find anywhere). Normally, what the user types must exactly match one of the MatchList phrases for a match to occur. By contrast, this option finds a match more often because it searches the entire length of the input text.


A list of zero or more keys, any one of which terminates the input when pressed (the EndKey itself is not written to OutputVar). When an input is terminated this way, ErrorLevel is set to the word EndKey followed by a colon and the name of the EndKey. Examples:

The EndKey list uses a format similar to the Send command. For example, specifying {Enter}.{Esc} would cause either ENTER, period (.), or ESCAPE to terminate the input.

To use Control, Alt, or Shift as end-keys, specify the left and/or right version of the key, not the neutral version. For example, specify {LControl}{RControl} rather than {Control}.

Although modified keys such as Control-C (^c) are not supported, certain keys that require the shift key to be held down -- namely punctuation marks such as ?!:@&{} -- are supported in v1.0.14+.

An explicit virtual key code such as {vkFF} may also be specified. This is useful in the rare case where a key has no name and produces no visible character when pressed. Its virtual key code can be determined by following the steps at the bottom fo the key list page.


A comma-separated list of key phrases, any of which will cause the input to be terminated (in which case ErrorLevel will be set to the word Match). Any spaces or tabs around the delimiting commas are significant, meaning that they are part of the match string. For example, if MatchList is "ABC , XYZ ", the user must type a space after ABC or before XYZ to cause a match.

Two consecutive commas results in a single literal comma. For example, the following would produce a single literal comma at the end of string: "string1,,,string2". Similarly, the following list contains only a single item with a literal comma inside it: "single,,item".

Because the items in MatchList are not treated as individual parameters, the list can be contained entirely within a variable. In fact, all or part of it must be contained in a variable if its length exceeds 16383 since that is the maximum length of any script line. For example, MatchList might consist of %List1%,%List2%,%List3% -- where each of the variables contains a large sub-list of match phrases.



1 or 0

Whenever the command is used without parameters, ErrorLevel is set to 0 if it successfully terminates a prior input, or 1 if there is no input in progress.

NewInput The input was interrupted by another thread that used the Input command.
Max The input reached the maximum allowed length and it does not match any of the items in MatchList.
Timeout The input timed out.
Match The input matches one of the items in MatchList.
EndKey:name One of the EndKeys was pressed to terminate the input. In this case, ErrorLevel contains the word EndKey followed by a colon and the name of the terminating key without braces, e.g. EndKey:Enter, EndKey:Escape, etc.



If this command is used while an input is already in progress in another thread, that input will be terminated and its ErrorLevel will be set to the word NewInput. After that (if parameters were given), the new input will commence.

While an input is in progress, new threads such as custom menu items and timed subroutines can still be created. Similarly, keyboard hotkeys are still in effect if the input is visible. If the input is not visible, only hook hotkeys can be triggered.

When a script first uses this command, the keyboard hook will be installed automatically if it isn't already present. Once that happens, the script becomes persistent, meaning that ExitApp should be used to terminate it.

Although not as flexible, hotstrings are generally easier to use than the Input command.



Hotstrings, InputBox, #InstallKeybdHook, Threads, StringCaseSense



; Wait for the user to press any key.  Keys that produce no visible character,
; such as the modifier keys, function keys, and arrow keys, are listed as end keys
; so that they will be detected too.
Input, SingleKey, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
; This is a working hotkey example. Since the hotkey has the tilde (~) ; prefix, its own keystroke will pass through to the active window ; (except on Win9x). Thus, if you type [btw (or one of the other match ; phrases) in any editor, the script will automatically perform an ; action of your choice (such as replacing the typed text): ~[:: Input, UserInput, V T5 L4 C, {enter}.{esc}{tab}, btw,otoh,fl,ahk,ca if ErrorLevel = Max { MsgBox, You entered "%UserInput%", which is the maximum length of text. return } if ErrorLevel = Timeout { MsgBox, You entered "%UserInput%" at which time the input timed out. return } if ErrorLevel = NewInput return IfInString, ErrorLevel, EndKey: { MsgBox, You entered "%UserInput%" and terminated the input with %ErrorLevel%. return } ; Otherwise, a match was found. SetKeyDelay, -1 ; Most editors can handle the fastest speed. if UserInput = btw Send, {backspace 4}by the way else if UserInput = otoh Send, {backspace 5}on the other hand else if UserInput = fl Send, {backspace 3}Florida else if UserInput = ca Send, {backspace 3}California else if UserInput = ahk Run, return