• Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

AutoHotkey Webinar 10/2021: Creating and Using AutoHotkey Functions

AutoHotkey webinar AutoHotkey functionsHour 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])
  • Round(Number[,N])
  • Trim()
  • StrSplit(String , [Delimiters, OmitChars, MaxParts])

Highlights:

  • 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
  • Global
  • Static
  • byRef

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

or this post from CodeProject

I made this video which shows how simple it can be.  You can download the script below

My updated AutoHotkey Excel function library

Over the years I’ve done a lot in Excel.  Often I leverage my Excel function Library which is, at best, a work in progress.   I commissioned Maestrith, author of AHK Studio, to review it.   We worked through what did & didn’t work plus optimized a few things.

AutoHotkey Excel Function Library

Streamline your code by Utilizing Includes in AutoHotkey

how to use Includes in AutoHotkeyAs I previously reviewed, functions in AHK rock!  The below video demonstrates how easy it is to use the utilize the includes 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\.

Includes in AutoHotkey

 

 

 

 

 

By using the #Include Directive you specifically tell AHK to “include” the file in your script.  Using Includes in AutoHotkey is an amazing way to keep your code clean and organized.

Using Includes in AutoHotkey