Is it actually possible to insert a line break in a message box text?
I have searched far and wide and everybody talks about 'n
or \n
but that does not work.
Can anyone give me an example of code that actually works?

- 14,885
- 4
- 25
- 52

- 167
- 1
- 2
- 6
-
It appears you're using an apostrophe/single quote which looks very close to the grave accent. That would be the cause of failure. It would be the same keyboard key as the tilde button on a standard English keyboard. – wetin Jun 25 '20 at 00:01
-
Can you accept the answer to close the question please? – Thierry Dalon Apr 22 '21 at 18:42
5 Answers
In AutoHotkey, the sequence
`n
(a backtick followed by an n
) indicates a newline.
For instance:
MsgBox, "line1`nline2`nline3"
Produces an output like:
line1
line2
line3
-
2Thanks! The word 'backtick' is the key. I was using a single quote mark instead and no wonder I was getting nowhere. – user2157155 Mar 31 '13 at 21:14
-
Is it possible to separate a particularly long 200+ character MsgBox string onto multiple lines? (i.e. `MsgBox This job may not have been added properly.\`nPlease manually attach the job once this script has finished.`) – Stevoisiak Sep 01 '17 at 20:38
You want a continuation section.
Here's an example script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
lorem =
(
Lorem ipsum dolor sit? Knowin' embark a sword tharrr. Much bucket har, avast, Flying Dutchmen shaft craft legend sails runnin'. Poopdeck barrel shaft, scimitar captain brothel. West poopdeck cannon-ball gunpowder deck. Much kill sink many scalawag. Davey east direction davey shaft direction avast scimitar off drunk travel, crew. Bottle scurvy, pirates a.
Strike stars, mast treasure. Arrrgh, boom bow strike her crows-nest brothel, bar be. 'Til ahoy bow smuggle stars crew mast myth head. Wreck many, bar sea scimitar har harbor. Other sea west bread death, raft poopdeck locker be matey ahoy?
Embark explosion patch scalawag washed-up rudder pirate devil be, mast, with. Raft death shipment drink, those. Myth raid east, Kraken stars raid cannon-ball with scimitar gold, avast. Bread together runnin'? Be dispatch, her ahoy be Flying Dutchmen. Ahoy bread myth. Flying Dutchmen vessel bottle, poopdeck.
)
msgbox %lorem%
Output:

- 318
- 3
- 7
Alternative #1: Call Msgbox with "( )" around your data.
Msgbox,
(
SUMMARY:
========================
TOTAL : ALL______: %ALL%
TOTAL : NON_BLANK: %TOT%
BLANK : B4 TRM: %B_F%
BLANK : AFTER TRM: %BAT%
DUPES :__________: %NTS% ;;num_tok_skip
UNIQUE:__________: %NTA% ;;num_tok_added
========================
)
;; Above prints out a table of values: ALL, TOT, B_F, BAT, NTS, NTA
;; The are variables defined elsewhere in my code I wanted a printout
;; in table from of.
Alternative #2: Here is an alternate method I use when creating blocks of text to be pasted from autohotkey. I just like the "CHR" command more than the back ticks.
global cr_char := CHR(13) ;AKA: 'r (return char)
global lf_char := CHR(10) ;AKA: 'n (newline char)
global windows_newline := cr_char . lf_char

- 3,611
- 30
- 17
You can use "r" in backtick.
> `r`
like:
::@ph::Content-Type:application/json
r
X-Auth-Token:

- 1,688
- 1
- 16
- 22
-
Great, but how is this answer different than https://stackoverflow.com/a/15725563/12349734 ? – MendelG Jul 14 '21 at 02:29
-
@MendelG look here: https://stackoverflow.com/questions/1761051/difference-between-n-and-r – Karol Zlot May 01 '23 at 04:12
The answer `n mentioned above was really helpful.
I think I tried numerous times to include something like {Enter}, but this solution works. (for the command line, otherwise, it leaves the last line unsent... )
;; standard galactic ;;
:*:myaliases::
(
alias ='alias'
alias ='cd'
alias ='less'
alias ='ls'
alias ='mkdir'
alias ='echo $(moontop)'
alias ='touch'
alias ='vim'`n
)
the :*: causes it to be evaluated immediatedly without having to hit space or enter, so it was annoying to have to hit enter again to evaluate the last line

- 11
- 2