As I previously reviewed, functions in AHK rock! The below video demonstrates how easy it is to use the utilize the include command in AutoHotkey to leverage functions & libraries that are not in your main file. Without using the include command AHK will first look in your local library, then look under the myDocuments\AutoHotkey\Lib\ folder and finally under path-to-running-AutoHotkey.exe\lib\.
By using the include command you can specifically tell AHK to look in a given file.
Include command in AutoHotkey
Functions in AutoHotkey rock! Some functions though have items that either 99% of the time are the same value or are things that you rarely use. In this case using optional parameters in AutoHotkey Functions is a great way to simplify your code! Just remember that the optional parameters have to be listed after all of the required parameters.
In the below video I demonstrate how to set defaults and pass optional params to an AutoHotkey function.
Optional parameters in AutoHotkey functions
In my initial video I talked through how & why to use AutoHotkey functions as well as how to return one value from a function. This video will demonstrate how to Return Multiple Values from AutoHotkey Functions via the byRef command. You can also return multiple values by returning an Object or an Array which can hold any-number of values.. The byRef command can seem a bit tricky at first, but it really is an easy way to return many values from a function. My next video will cover using the Include command
Return multiple values from AutoHotkey functions with byRef
AutoHotkey functions are a true gem that help streamline your code, make it more readable, easier to maintain, and avoid conflicts with other variables (because their scope is local by default. They take a little practice getting used to however they can save a ton of time and allow for re-using a ton of code. Don’t get hung-up on writing them at the beginning of your script. Often I go back after writing my script and realize I should have written a function in place of a subroutine.
My first video on AutoHotkey functions explains why & how you can use them.