Hour 1: Intro to Functions
Hour 2: Q&A Styles and helping Attendees
Script Highlight: Times around the world by jeeswg
The Automators’ Podcast
#113: 7 reasons to talk to others about your programming
#114: 5 tips how to reduce the amount of personal support you provide
#115: What is an idea worth? How much $ should you pay the “idea person”?
Resources presented in Webinar
What is a Function?
- A function is similar to a subroutine (Gosub) except that it can accept parameters (inputs) from its caller.
- In addition, a function may optionally return a value/values to its caller.
66 Built-in AHK Functions https://www.autohotkey.com/docs/Functions.htm#BuiltIn
- Polythene’s Command functions https://github.com/Paris/AutoHotkey-Scripts/blob/master/Functions.ahk
- jeeswg commands as functions (AHK v2 functions for v1) https://www.autohotkey.com/boards/viewtopic.php?f=37&t=29689
Some main benefits of Functions
- They can be used without storing value
- You can have multiple on one line / nest
- Scope is limited (both a blessing and a curse)
- You create functions to “wrap” complex code which greatly simplifies it’s usage
- Via a DLL call you can leverage TONS of functions outside AutoHotkey!
- Variadic functions take a “variable” number of parameters
Built-in AutoHotkey functions
- Using built-in Functions (here are a couple examples)
- SubStr(String, StartingPos [, Length])
- StrSplit(String , [Delimiters, OmitChars, MaxParts])
- Positional parameters (the order matters they’re not named parameters)
- Required parameters
- Optional parameters
Creating your own Functions in AutoHotkey
- Why you want to create them
- Defining a Function verse Calling a function
- Working with SCOPE
What we’ll cover:
- Accessing variables outside your AutoHotkey function
- Passing parameters
- Setting default values for your parameters
- Returning value
- Returning more than 1 value (byRef & Objects/Arrays)
- Using the #Includes directive and Function Libraries
Biggest things that will trip you up!
- Scope seems like a design flaw however it is a great benefit. Most noobs (and even seasoned programmers) will sometimes forget they are inside a function and try and access a variable outside the function
- Forgetting you returned an object and trying to access it as a variable
- Making something Global and then reusing the variable in something else
Skins & Styles – Dimitri (I’ll work on a working example to include here)
Dimitri Geertz joined the webinar and demonstrated his work using the skinsUSkin.dll.
You can learn more about it here in the forum post
I made this video which shows how simple it can be. You can download the script below