e following snipped assigns a formatted piece of text to a variable creating a WYSIWYG multi-line text entry:
Help = ( To Calibrate Range: 1. Cursor at start point — CTRL+LButton and hold. 2. Drag to end of scale and release. 3. Enter length of scale and units i.e. 10 miles. Manual Calibration: CTRL+ALT+Z To Measure Distance: 1. Cursor at start point — SHIFT+LButton and hold. 2. Drag to end of measurement and release. 3. Distance displayed and saved to Clipboard. CTRL+ALT+F12 for this Help Message. ) MsgBox, 0, MouseMeasure Help, % Help
The MsgBox command displays the contents of the variable Help exactly as originally typed.
Note: You can also use the
:= type of variable assignment, but you must enclose the section in quotes:
Help := " ( . . Multiline Text . . )"
… although to display a single double-quote mark (
") and prevent runtime errors, you must now escape any quotation marks in the text with a preceding quote (
Using Multi-line Continuation in Commands
Any AutoHotkey command which accepts plain text can use the same type of multi-line continuations. For example, in the same MouseMeasure.ahk script, the updating ToolTip command displaying the current pixel distance and the converted unit length (see image) uses the following formatting:
ToolTip [%dx%:%dy%]`n%dist% px`n%distCalibrated% %units%
Using section continuation, you can replace the above line with the following WYSIWYG formatted section:
tooltip, ; comma required ( [%dx%:%dy%] %dist% px %distCalibrated% %units% )
Note: You can include the traditional double-percent-sign text replacement (
%var%) inside multi-line continuation sections.
While you can use this technique with any command that uses plain text parameters (or expressions), inserting so many lines in the middle of a command tends to make the code less readable. You may find it easier to read by saving the multi-line text to a variable, then using that variable as either a text substitution (
%var%) or forced expression (
Multi-line Section Continuation Options
AutoHotkey offers options when using section continuation. Place the options on the same lines as the open parentheses:
Help = (LTrim Comments To Calibrate Range: ; Instructions for calibration 1. Cursor at start point — CTRL+LButton and hold. 2. Drag to end of scale and release. 3. Enter length of scale and units i.e. 10 miles. Manual Calibration: CTRL+ALT+Z ; Calibration GUI To Measure Distance: ; Instruction for measuring distance 1. Cursor at start point — SHIFT+LButton and hold. 2. Drag to end of measurement and release. 3. Distance displayed and saved to Clipboard. CTRL+ALT+F12 for this Help Message. ) MsgBox, 0, MouseMeasure Help, % Help
Line 2 above includes the options
LTrim removes any space or tabs found to the left of the text and
Comments prevents the display of the comments appearing on lines 3, 9, and 11 (as shown at right).
Multi-line continuation section options include (from online AutoHotkey documentation):
- Join: Specifies how lines should be connected together. If this option is omitted, each line except the last will be followed by a linefeed character (`n). If the word Join is specified by itself, lines are connected directly to each other without any characters in between. Otherwise, the word Join should be followed immediately by as many as 15 characters. For example,
Join`swould insert a space after each line except the last (“`s” indicates a literal space — it is a special escape sequence recognized only by Join). Another example is
Join`r`n, which inserts CR+LF between lines. Similarly,
Join|inserts a pipe between lines. To have the final line in the section also ended by a join-string, include a blank line immediately above the section’s closing parenthesis.
Known limitation: If the Join string ends with a colon, it must not be the last option on the line. For example,
(Join:is treated as the label “(Join” and
(LTrim Join:is unsupported, but
(Join: Cis okay.
- LTrim: Omits spaces and tabs at the beginning of each line. This is primarily used to allow the continuation section to be indented. Also, this option m