#EscapeChar (and explanation of escape sequences)

AutoHotkey

#EscapeChar (and explanation of escape sequences)

Changes the script's escape character (e.g. accent vs. backslash).

#EscapeChar NewChar

Parameters

NewChar

Specify a single character.

Remarks

The escape character is used to indicate that the character immediately following it should be interpreted differently than it normally would.

The default escape character is accent/backtick (`), which is at the upper left corner of most English keyboards. Using this character rather than backslash avoids the need for double blackslashes in file paths.

Escape Sequences (when accent is the escape character)

Type This To Get This
`,

, (literal comma).

Note: Commas that appear within the last parameter of a command do not need to be escaped because the program knows to treat them literally (but it is best to escape them anyway, for clarity). The same is true for all parameters of MsgBox because it has smart comma handling.

`% % (literal percent)
`` ` (literal accent; i.e. two consecutive escape characters result in a single literal character)
`;

; (literal semicolon).

Note: It is not necessary to escape a semicolon which has any character other than space or tab to its immediate left, since it would not be interpreted as a comment anyway.

`:: :: (literal pair of colons). [v1.0.40+]: It is no longer necessary to escape these, except when used literally in a hotstring's replacement text.
`n newline (linefeed/LF)
`r carriage return (CR)
`b backspace
`t tab (the more typical horizontal variety)
`v vertical tab -- corresponds to Ascii value 11. It can also be manifest in some applications by typing Control+K.
`a alert (bell) -- corresponds to Ascii value 7. It can also be manifest in some applications by typing Control+G.
`f formfeed -- corresponds to Ascii value 12. It can also be manifest in some applications by typing Control+L.
Send When the Send command or Hotstrings are used in their default (non-raw) mode, characters such as {}^!+# have special meaning. Therefore, to use them literally in these cases, enclose them in braces. For example: Send {^}{!}{{}.
"" Within an expression, two consecutive quotes enclosed inside a literal string resolve to a single literal quote. For example: Var := "The color ""red"" was found.".

Related

The following rarely used directives also exist; their usage is shown in these examples:

#DerefChar #  ; Change it from its normal default, which is %.
#Delimiter /  ; Change it from its normal default, which is comma.

Example

#EscapeChar \  ; Change it to be backslash instead of the default of accent (`).