7

The AutoHotkey Beginner Tutorial starts off with an example using the Send command, with the command and its argument separated by a comma:

^j::
   Send, My First Script
Return

...

SEND is the command, anything after the comma (,) will be typed.

Later, it gives an example of the MsgBox command with no comma:

esc::
    MsgBox Escape!!!!
Return

Experimentally, it seems that including or omitting the comma makes no difference to the behaviour of a command, at least in these simple cases. We can change whether the comma is included in both examples above and the command still works: MsgBox, Escape!!! works, and so does Send My First Script.

Are there circumstances in which the syntax requires the comma (or forbids it)? Does the inclusion of the comma alter the semantics of the command in any way? Why are both syntaxes allowed?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459

2 Answers2

8

The comma (,) in AutoHotkey is a separator. The first (between the command and the first parameter) is completely optional in most circumstances:

Tip: The first comma of any command may be omitted (except when the first parameter is blank or starts with := or =, or the command is alone at the top of a continuation section). For example:

MsgBox This is ok.
MsgBox, This is ok too (it has an explicit comma).
Community
  • 1
  • 1
Nepho
  • 1,074
  • 1
  • 11
  • 32
2

To expand on this matter, quote from commands and commas:

There are two ways of writing commands in AHK v1:

; initial commas
Cmd, Arg1, Arg2
Cmd, , Arg2

; no initial commas
Cmd Arg1, Arg2
Cmd , Arg2

The no initial comma style can look a bit odd, confusing even, when you omit the first parameter.

Wenfang Du
  • 8,804
  • 9
  • 59
  • 90