Now it is time for Reserved keywords
So far, we have covered an important concept called variables.
We discussed how to use the operator := to specify values.
We also looked at what to name the variables.
Like True and False are the names of two built-in variables.
There are many other keywords supported
By AHK which are reserved and used for a different purpose.
Every programming languages provides
Their own set of reserved keywords
But there is one important &
Common rule in all the programming languages and it is
We cannot use a reserved keyword to name our variables
Which means in AHK we cannot name our variable things like a_temp or A_scriptdir
Rather reserved keywords can only be used to specify, call or get a build-in function, command, or variable.
Reserved keywords example:
If you try to use any reserved keyword for the purpose of variable name, then you will get a syntax error.
A_AhkPath := 10 MsgBox, Value of A_AhkPath = % A_AhkPath%
When you run the above script, it produces the following error −
……
C:\tester.ahk (1) : ==> Not allowed as an output variable.
Specifically: A_AhkPath
……
Let’s now give a proper / allowed name to our variable, then the above script should work and execute successfully −
count := 10 MsgBox, Value of count = %count%
That script will not give out any error and will simply work and show you the Msgbox with the value of count
Reserved Keywords in AutoHotkey
As an example here is a table having almost all the reserved variable names in Autohotkey – ( there are also function names and commands )
a_ahkpath | a_ahkversion | a_appdatacommon | a_appdata |
a_autotrim | a_batchlines | a_carety | a_caretx |
a_computername | a_controldelay | a_dd | a_cursor |
a_ddd | a_dddd | a_desktop | a_defaultmousespeed |
a_desktopcommon | a_detecthiddentext | a_endchar | a_detecthiddenwindows |
a_eventinfo | a_exitreason | ||
a_formatfloat | a_formatinteger | a_guievent | a_gui |
a_guicontrol | a_guicontrolevent | a_guiheight | |
a_guiwidth | a_guix | a_hour | a_guiy |
a_iconfile | a_iconhidden | a_icontip | a_iconnumber |
a_index | a_ipaddress1 | ||
a_ipaddress2 | a_ipaddress3 | a_isadmin | a_ipaddress4 |
a_iscompiled | a_issuspended | a_language | a_keydelay |
a_iscritical | a_isunicode | errorlevel | a_ptrsize |
a_lasterror | a_linefile | a_loopfield | a_linenumber |
a_loopfileattrib | a_loopfiledir | a_loopfileext | |
a_loopfileshortname | a_loopfileshortpath | a_loopregsubkey | a_loopfiletimecreated |
a_loopfileshortpath | a_loopfilefullpath | a_loopfilename | a_loopfilelongpath |
a_loopfilesize | a_loopfilesizekb | a_loopfiletimeaccessed | a_loopfilesizemb |
a_loopfiletimemodified | a_loopreadline | a_loopregname | a_loopregkey |
a_loopregtimemodified | a_loopregtype | a_min | a_mday |
a_mm | a_mmm | a_mon | a_mmmm |
a_mousedelay | a_msec | ||
a_mydocuments | a_now | a_numbatchlines | a_nowutc |
a_ostype | a_osversion | a_programfiles | a_priorhotkey |
a_programs | a_programscommon | a_screenwidth | a_screenheight |
a_scriptdir | a_scriptfullpath | a_scriptname | |
a_sec | a_space | a_startmenucommon | a_startmenu |
a_startup | a_startupcommon | a_tab | a_stringcasesense |
a_thishotkey | a_thismenu | a_thismenuitempos | a_thismenuitem |
a_tickcount | a_timeidle | a_timeidlephysical | |
a_timesincepriorhotkey | a_timesincethishotkey | a_titlematchmodespeed | a_titlematchmode |
a_wday | a_windelay | a_workingdir | a_windir |
a_yday | a_year | a_yyyy | a_yweek |
clipboard | clipboardall | comspec | |
a_ispaused | a_thisfunc | a_thislabel | programfiles |
a_temp | a_username | FALSE | TRUE |
Now memorize:
I know you cannot memorize all these names 🙂
But as you see many of them start with (a_)
So keep away from using that in your own variable names
Also I listed them down for your reference
And to Show/Explain the concept of reserved keywords
And there are most likely more then the ones I posted here.
So just be mindful while giving a name to your variable
You should not use any of the above mentioned reserved ones.
AutoHotkey does not really have any official best practices when it comes to anything like a naming convention!
Many users do however:
Take a stand in things like this
And at least a few things do come up again and again
When looking at most AHK code
Examples of things like that is:
Indention, camelCase and using “saying” names when making variables or functions.
Your also welcome to read my take/thoughts on some best practices in AutoHotkey
The online AutoHotkey forum is always a good place to get help if you see errors or issues with things like:
- Not allowed as an output variable.
- Variable name contains an illegal character
- Line does not contain a recognized action.
And many others
Please use the comments or my contact form if you need help with this or have something to add