AHK: How to Make a User Interface

I loathe ComputerSpeak.

Missed commas. Misspelled commands. A { instead of a ( because those bastards look exactly alike. Opening the script guarantees that I will make at least one of these errors while updating the code to do something slightly different.

So in order to combat this, I’m making my script a muzzle.

Call it a GUI (Graphical User Interface), call it a window, call it a box-it’s all the same to me. Essentially I’m turning this jumble of script on the right to this nice, soothing thing on the left.


In the interest of keeping it simple, let’s make the simplest GUI possible and build up from there.

The Simplest Box Possible

Important Commands to Note:
Gui, Add, Text, MoreAdvancedOptionsHere , TextYouWantDisplayed
Gui, Show

These commands will enable you to make your computer say whatever you want. Here’s an actual script in Notepad.


And what you’ll see when you run it.


A Slightly More Complicated Box

Important Commands to Note:

Gui, Add, Checkbox, Variable4UserInput, TextToDisplay
Gui, Add, DropDownList, Variable4UserInput, Option1 | Option2
Gui, Add, Radio, Variable4UserInput, TextToDisplay
Gui, Add, Button, MoreAdvancedOptionsHere, TextToDisplay

These commands are meant to get input from the user. In the interest of keeping it simple, as scripted below, they don’t actually do anything. They just display the checkbox, the dropdown list, the radio and the button. It’s all the beauty of a BMW without the engine.


If all has gone well, you’re fancy, new user interface will look like this:


A Still Comprehensible Box

Now, we don’t want the box just to be pretty, it’s got to be useful. I want to be able to select from a menu and make something happen.

When the user makes a choice, that’s stored in a variable. Remember the code for drop down lists? Gui, Add, DropDownList, Variable4UserInput, Option1 | Option2. You get to pick whatever name you want for the variable (red text), but it has to start with the letter v. Below I’m calling it vDropDown.

Important Commands to Note:

Do This

MsgBox TextToDisplay + %Variable% (to display a variable)

Gui, Submit (to close the box and store all variables)



Now with just 10 lines of code, your computer can say hi. You’ve also tapped into the awe-inspiring power of variables. Variables open all kinds of doors. Code lets you talk to computers, but variables let you exchange information with anyone using the code. Here, it’s a simple “I would like to be referred to as Your Highness,” but it could potentially be anything. Here’s the end result:




Tagged , , , , , , , ,
%d bloggers like this: