Friday 26 August 2022

Directives vs Commands in AHK/AutoHotKey

I couldn't find a direct answer to this question, so thought, once I'd managed to piece it together I'd post it here for any future searchers.

In general programming a command is a specific type of directive which tells a programme to do a particular task. However, AHK plays by its own rules. 

According to Frankie Bagnardi, in AHK "Directives are processed just before the script starts and allow you to customize AutoHotkey’s behaviour". There are two types. The first is just the bits of code at the top of a script, but they are also anything that starts with a #.

So in AHK directives are the bits of code starting with a # (hashtag/pound sign in the US)

So if you use, say, #IfWinActive partway down your code, the the commands that follow it will be specific to that context, until you turn it off (by using the same directive, with no conditions/parameters afterwards).

Directives are a type of commands which use a # to create a context. Bits of code that aren't functions, expressions, variables, parameters, text etc. are all commands, (e.g. Send, Sleep, Run, MsgBox). Directives are a specific subset of the available commands.

And, for the sake of completion, functions are those bits of code that come with brackets(parentheses). Expressions are bits of maths.

- If I've got this wrong, please let me know in the comments without shouting or calling me an idiot...

No comments:

Post a Comment