MasterFocus' AHK Code Catalog

This is where I intend to keep track of all my AutoHotkey scripts and code snippets.
This page is not designed to be beautiful. Just functional. ;)

Last update: 23/may/2014
[ checking my current webpages and updating hyperlinks ]

# License

Unless differently specified, all my code is usually licensed under GNU AGPL v3.0
Please make sure you refer to this page and/or one of my webpages when reproducing any code.
Although it's not really necessary, I'd appreciate if you contact me when using my code.

# Compatibility

All my code is intended to be compatible with AutoHotkey v1.0.* by default.
Usually, it means my code may also work on v1.1.* and other brands.
I will try to create a detailed "compatibility table" for each piece of code in the future.

# Contact / Links

To contact me, send me a Private Message on or
I'm currently more active on which is a "community-driven" initiative.
Sometimes (rarely), you may find me on Freenode's IRC at channels #ahk and #ahkscript (nickname: MasterFocus)

Homepage (
Homepage (GitHub):
GitHub profile:  
Homepage (


# Libraries

General Proxy-Dll Functions a.k.a. GPF
      Overlay DirectX8/9 applications with multiple texts and one image. Also takes screenshots and shows FPS.

Type Functions
      A group of functions to check, retireve and compare AHK variable types.
                FORUM TOPIC --- Featured in ahkstdlib


# Functions

      Waits for a pixel to be of a certain color. Features optional timeout.
                FORUM TOPIC --- Featured in ahkstdlib

      Retrieves name, handle, position and size of all controls from a matching window.
                FORUM TOPIC

      Weighted random. Specify a weight for each field: the returned value is the number of the randomized field.

      Creates any kind of random content for a variable. Options include type (AHK variable type), length and ASCII range.
                FORUM TOPIC --- Reproduced here: {1}

      Retrieves the letter of the first drive that matches the given label.
                FORUM TOPIC

      Clears the specified consecutive elements of an array without accidentally creating new elements/variables.
        [ probably obsolete as AHK v1.1.* supports real arrays (objects) ]
                GitHub folder

      Retrieves a certain number of random items or all items containing a substring with optional matching position.
        [ currently outdated - I will upload a new version later ]
                FORUM POST

      Returns a sorted version of an input list based on a RegEx needle and a precedence order for any subpatters.
                FORUM POST

Dec2Roman + Roman2Dec
      A pair of functions created to perform convertions between decimal and roman numbers.
                FORUM POST

      Finds multiple instances of a specified image on screen and returns a list of matching coordinates.
        [ the current implementation is WRONG! I will discontinue this function and upload a replacement later ]
                FORUM POST

GetTuples + Combine
      A useful pair of functions for arrangements, tuples, combinations, permutations...
        [ related work by other users can be found within the topic ]
                FORUM TOPIC

      Automatically cycle through a list of elements with ease. No need to declare a bunch of variables.
                FORUM TOPIC --- Mentioned in camerb's AHK repository

      Simple short function which makes a random choice out of a given set.
                FORUM TOPIC

      Moves mouse from one point to another using an ellipse instead of a straight line. Based on previous work by Wicked.
                FORUM POST

      Allows moving a target window to specific place on the screen, like TOPLEFT, BOTTOM or CENTER.
                FORUM POST

      Moves the mouse using a random trajectory, which is in fact a random Bézier curve.
                FORUM TOPIC

      Yet another wrapper for the InputBox command.
                FORUM TOPIC


# Templates

      Use a simple GUI with checkboxes to work with selectable items.
                AHK FILE (outdated!) --- Modified example

WinTrigger (former OnOpen/OnClose)
      Perform actions upon (de)activation or (un)existance of certain windows/programs.
                FORUM TOPIC --- Reproduced here: {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8} --- Old version

Grid Template
      This template is useful for finding the best way to visually distribute elements into a grid shape.
                FORUM POST

Benchmarking Template
      Specially designed to compare two routines and show detailed results of the bechmark, possibly electing a winner.
        [ licensed under CC BY-SA 3.0 ]
                FORUM POST


# My contributions to RosettaCode
All code submitted to RosettaCode becomes available under GNU FDL 1.2 by default.

You can find an up-to-date detailed list here:

Hailstone Sequence
      Calculates the Hailstone sequence (and its length) for a provided initial number.
                SUBMITTED CODE --- AHK FILE

Price Fraction
      A specialised rounding function to work according to a certain table.

Number Reversal Game
      A game where you get a jumbled list of numbers (1-9) and must attain the ascending order by only reversing them from the left side.

String Repetition
      An example showing the simplest way to repeat a string in AutoHotkey.

Dot Product
      A simple function which computes the dot product (aka scalar product) of two vectors.

The N-Queens Problem
      A function that uses a few global variables and solves the N-Queens Problem.

Missing Permutations
      Function designed to find one or more missing permutations of a given set.

HQ9+ Interpreter
      A small simple function which executes a HQ9+ code.
                FORUM POST --- AHK FILE


# Other scripts and code snippets

Bejeweled Autoplay
      A framework developed to autoplay a free Flash version of Bejeweled 2.
        [ the game webpage has already been redesigned, possibly affecting automation ]
                FORUM TOPIC

Drawing a spirograph + CoordSpirograph()
      Helper script for drawing a customizable spirograph.
                FORUM TOPIC

WinLimit a.k.a. XPSnap / XP Snap
      "A script that mimics Windows 7 Aero Snap", as stated in DataLife's original post.
        [ however, it doesn't change the size of the window (on WinXP) ]
                FORUM POST

VK() a.k.a. Hotkey2Virtual Key
      A function to convert a hotkey into its virtual key code. Created in conjunction with other users.
                FORUM TOPIC


Reminders to myself:
[1] add GetWindowsByStyle()
[2] add Gdip_ImageSearch()
[3] add CenterControl()
[4] add the "mantain GUI aspect ratio" script
[5] add all the following references to my stuff: