AHK: What is an Array?

Arrays are a damn godsend. More specifically, they’re an easy way to deal with large lists. Why is this useful you ask? Imagine you want to run the same code on multiple items. The items could be numbers, letters, words, full sentences—anything.  By putting those things in a list, or an array, you can loop through hundreds, even thousands, of items with just a few lines of code.


So say, for instance, you wanted to rotate the letters in the alphabet up by a certain number. You could do that if/else coding all 26 letters by hand like I did last week. OR, you could create an alphabet array in AutoHotkey.

abcArray := [ “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z” ]

A quick note:
The index is just an item’s position in the array. It can be used for easy access with [ ]. In this case, abcArray[1] = a,  abcArray[2] = b, abcArray[3] = c and so on. “a”, “b”, and “c” are called values.

The beauty of indexes is that they can be variables. That comes in handy when you’re changing the positions of values in your array. Here, I want everything shifted up so that abcArray’s 2nd letter is equal to rotatedArray’s 1st letter. Then I’m just adding 1 to each cycle of the loop to get positions for the rest of the alphabet.

The code below also uses a FOR LOOP to display the array at the end. Array FOR LOOPs  in AutoHotkey look a bit different. Here’s the template:

For index, value in Array
Do This with %index% or %value%

A breakdown of the code:


Which will result in:


While that may seem startlingly simple now, that little script took approximately 4 hours of me bashing my head against a wall because of 2 tiny mistakes.

Things to Check When Arrays Don’t Work



Once you’ve got a shifted alphabet, the Caesar Shift becomes significantly easier to script in AutoHotkey. An updated code is coming soon.

Tagged , , , , ,

2 thoughts on “AHK: What is an Array?

  1. Very useful bit of information!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: