• Intro to AutoHotkey HotStrings with AutoHotkey Intermediate AutoHotkey GUIs are Easy with AutoHotkey Intro to DOS & AutoHotkey AutoHotkey FAQ AutoHotkey FAQ

Intermediate Objects & Classes: Level-up to Object Oriented Programming

Promo Thumbnail 1.1.1 guarantee

Jean Lalonde:

“AutoHotkey is an incredible development tool and this course helped me unlock its most powerful tools.  Thanks to its clear explanations and practical examples, I now have a clear understanding of objects, classes, COM objects, etc. and know how to use them in my AHK projects.”


Dillon DeRosa:

“The Intermediate Objects course is packed full of knowledge! Isaias shows a deep understanding of objects and presents them in a way that’s simple to engage with. After learning from this course I now have a complete understanding of why and when I should use objects and classes. Above all else, this course shows that you don’t need years of study or a degree in coding to learn advanced concepts from classes and additionally DLL, or ComObjects. The sheer length of this course is worth every penny. I wish it was offered years ago to save me from many coding pitfalls.”

Course Length ~4 Hours

what are objects (8)

  • 00-Why you should learn classes
  • 01-what are objects
  • 02-arrays
  • 03-objects
  • 04-properties
  • 05-key value vs properties
  • 06-key value vs properties v2
  • 07-methods

function refresher (5)

  • 08-function definition and scope
  • 09-parameters
  • 10-optional parameters
  • 11-static variables
  • 12-variadic functions

types of arrays and how to iterate over them (3)

  • 13-types of arrays
  • 14-looping objects
  • 15-looping objects v2

class notation (7)

  • 16-class notation
  • 17-class inheritance
  • 18-new & delete methods
  • 19-meta-functions
  • 20-property definitions
  • 21-the this object
  • 22-class variables


  • 23-inheritance

comobjects (4)

  • 24-comobjects
  • 25-httpRequest
  • 26-vbscript regex
  • 27-nuances

examples (8)

  • 28-understanding classes without documentation
  • 29-class hierarchy
  • 30-converting function libraries to classes
  • 31-polymorphism
  • 32-apicall 1
  • 33-apicall 2
  • 34-apicall 3
  • 35-GDI Conversion

Intro who we are / what you’ll learn

  • Why you should learn objects
  • How they can help you / Opens up doors *
    • Have “templates” for things you create multiple instances of*
    • Dot notation to easily access, reference, etc.*
    • Can add methods properties*
    • Organize your code into projects that make sense*
    • Etc. (all high level / not coding)

What are objects

Objects can be defined as a collection of variables and functions that are related to each other.

They have members, and in autohotkey the most common members of an object are:

  • keys
  • items
  • Properties
  • Methods

What can we do with objects

  • Set and Get key values
  • Set and Get item values
  • Set and Get property values
  • Call methods

All those members can only be accessed by using object notation and are related only to the object being used in the statement.


They are “stand alone” values that are grouped in a list.


They can be seen as definition of a term that will have a related value assigned to it. A very good analogy would be words in a dictionary. Each word would be a key and the definition of it would be the value assigned to that word.


They can be seen as variables that can hold specific values related to the object.


Those are actions that can be performed by the object.

Functions Refresher

Methods act exactly the same as functions but they are contained by their object.

Object Types


An array can be described simply as a list of items related to each other. Each item has an index which indicates its position in the list, and a value which is the data that we want to access.


Associative Array

An associative array is also a list, but each item is a keyvalue pair.

In this context the index is no longer a number because the position of the item is irrelevant. Usually, you just want to get the value for a specific item by just naming it instead of referring to its position.


Multidimensional arrays

  • How to create them
  • How to access them

Maps on AHK v2

AHK v2 brings associative arrays that are more consistent with what they actually do. This brings changes as to how literal object definitions work.

OOPS Principles

  • Polymorphism
  • Inheritance
  • Encapsulation
  • Abstraction

OOPS Advantages and Disadvantages


  • Reusability
  • Security
  • Maintenance
  • Inheritance


  • Beforehand planning of entities that should be modeled as classes.
  • OOPS programs are usually larger than those of other paradigms.
  • Even though OOP systems resemble the real world in their logical entities, it might take some time to get the hang of thinking about the flow of your code in terms of classes and objects.
  • Steep learning curve.

Functional Programming Concepts and Terminology

  • Predefined functions
  • Modularity
  • Recursion

Advantages and Disadvantages


  • Easy
  • Simple
  • Generalized
  • Reliable
  • Lazy evaluation


  • Using recursion for every iteration operation is unintuitive, as compared to using while and for loops.
  • Reduced performance because of immutability – especially when having to duplicate large data structures even for making small changes.
  • Difficult or inefficient to perform recursion without letting variables be updated (immutability).
  • Procedural programming code is not reusable. You’ll have to replicate the code implementation across different programs or files.
  • Not easy to scale up or extend for larger applications.
  • Not secure, because of visibility of data across the whole program.

Why should we use objects then?

Objects allow us to group related pieces of code together to make it easier to understand. It also allows for modular code which is easier to debug or modify when properly done.

What if I want to create my own object

It is possible to create custom objects that do more than what the standard objects do. It is especially useful when creating custom types of data structures.

Custom objects can be derived from an existing object just to modify how the original object works without touching the original code. This allows for modular code which allows for greater code stability.

What is a class

A class is code that defines a custom object. It can be used to extend an existing class as well.

Think of a class as a template that can be used to create user defined objects.


Relationship between Objects and Classes

In autohotkey an object is the variable type that we are referring to when scripting. It falls in the same category as a string or an integer. Is just the way how data is grouped and tells us what we can do with that data. For example, you can’t do math on a string.

And a class is simply a way to define custom object.

How can we define objects

Automatically called functions

  • __New()
  • __Delete()

The this object

The easy way to understand it is that this is a special parameter that methods and properties of an object receive that contain the object itself. It allows the methods to access variables that belong to the object or call methods inside the object itself.

Defining variables

Variables are defined as any other part of an AutoHotkey script, but they belong to, and can be accessed only by the object being defined.

Defining Class variables

You can also create variables that are belong to the object class itself. To create them you can use the static keyword.

They are separate from the instance variables that belong to each copy of the object and can only be accessed by naming the class to assign it.

Differences between instance variables and class variables

Instance variables belong to the copy of the object. Each object has its own copy of it and can modify it separated from the other objects.

Defining properties

Properties and instance/class variables might look very similar when calling it in object notation, but they have a key distinction. Properties offer complete control as to what will happen when you set or get the values.

Defining methods

Methods can be defined and behave the same as functions, but they belong to the object itself and can access a hidden parameter called this which contains a reference to the same object that called the method allowing access to the instance variables and methods inside the method itself.

Meta functions

  • __Set()
  • __Get()
  • __Call()

What is a COMObject

It is an interface to an object that has been implemented in a different language. By using a com object you can use an object from a different programming language but using the syntax in the language you are programming in.

Why would I use a COMObject

We don’t need to reinvent the wheel, it is better to use tools that already exist and that are better maintained. Usually, the objects being used are more robust and stable than creating a tool yourself.

Which objects are available

AHK PowerShell

Using the documentation


Using an object in Autohotkey

httpRequest @AHK Forums

VBSCript.regex @AHK Forums


Variables and return values must conform to the receiving language’s expectations. It would help if you had, at least basic knowledge of the language the ComObject was created in. You need to have a lot of patience.


Comments are closed.