Use BoundFunc Object [Func.Bind()] to Pass GUI Control Data (An AutoHotkey GUI Revelation)

Added as a Special Feature to AutoHotkey V1.1, You Can Quickly Bind Unique Data to GUI Controls for Passing to Functions—It’s Even Easier in V2.0. Add This One to Your Bag of AutoHotkey Tricks!

Sometimes in my explorations, I come across an unexpected gem. I dig into many aspects AutoHotkey merely because they exist—having no idea how a technique might affect my scriptwriting. Whenever I uncover a feature that switches on a light, I must admit I get a little excited. Interestingly, if I had not been rummaging through AutoHotkey V2.0, I may not have ever understood the significances of this latest revelation for GUI pop-up windows in V1.1 scripts.

*          *          *

GraphicSoundsIn a GUI (Graphical User Interface) pop-up window, passing the right data to a gLabel subroutine (or function) from a GUI control can get complicated. A couple of the more common methods includes calling the Gui, Submit command to store control values or using a technique for capturing control information, such as the MouseGetPos command or the special gLabel alternative function:

 CtrlEvent(CtrlHwnd, GuiEvent, EventInfo, ErrLevel:="")

While I can usually find a way to solve the data passing problem, I often find the answer awkward. Continue reading


Write Less Code with Database Driven Apps (AutoHotkey Script Design)

Use Simple Database Files to Both Write AutoHotkey Code and Create Flexible Scripts

GraphicSoundsIn the last blog, I introduced a simple AutoHotkey app I call PictureSounds.ahk. When the user clicks on an image, AutoHotkey seeks the name of the sound file in an INI lookup table, then plays it. The script uses the image file name as the INI file Key. After loading a series of images, the script plays a different sound for each image. (It even plays videos!)

Using the INI file as a lookup table saved me from writing a different subroutine (or at least If condition) for each Picture control in the GUI window. Now, I show how to use that same data file to write the command code lines for adding the images to the pop-up files. Continue reading

Comparing Today’s AutoHotkey Version 1.1 and the Future Version 2.0 (Part 5—Replacing V1.1 gLabels with V2.0 GuiControl.OnEvent())

AutoHotkey Version 2.0 Drops the GUI gLabel in Favor of the Object OnEvent() Function

In AutoHotkey V1.1, the primary method for adding action to GUI pop-up windows employs the gLabel inserted into a GUI control’s options. As AutoHotkey moves to object-oriented programming in V2.0, the Gui.OnEvent() function replaces gLabels.

Launch Window V2In AutoHotkey V2.0, each GUI control responds to different Gui Events. For example, with the Gui Button control, you can register OnEvent() functions for Click, DoubleClick, Focus, and LoseFocus, while the Edit control directly supports Change. You register each type of initiating action you use with the OnEvent() function. In fact, you must register an event before AutoHotkey will respond. Continue reading

Comparing Today’s AutoHotkey Version 1.1 and the Future Version 2.0 (Part 4—Fixing %Var% Variable Replacements)

With the Removal of Most Forms of %Var% Variable Replacement from AutoHotkey V1.1, Expressions in V2.0 GUI Functions Require Special String Concatenation Attention

In the previous part of this series on “Comparing Today’s AutoHotkey Version 1.1 and the Future Version 2.0 (Part 3—RegExs for Converting to V2.0)“, I introduced Regular Expressions (RegEx) for converting certain AutoHotkey V1.1 commands into V2.0 functions. While generally effective, the conversions left any %var% variable replacements untouched. Continue reading

Comparing Today’s AutoHotkey Version 1.1 and the Future Version 2.0 (Part 3—RegExs for Converting to V2.0)

When and If the Time Comes, Regular Expressions (RegEx) Can Help with the Conversion Process from AutoHotkey V1.1 to V2.0

Identified by the (v1,v2) on the right side of the script name in the index, I’ve converted a few of the script on the Free AutoHotkey Script page from AutoHotkey V1.1 to the alpha version of V2.0. At first, I reworked a copy of a script one line at a time. Then I speeded up the process with a couple of Regular Expressions (RegEx) used in conjunction with Ryan’s RegEx Tester. While I continued working one line at a time, I could quickly reformat the entire line at once—mostly. Rather than tediously rewriting a command character by character, the RegEx provides a format which needs very little additional editing.

(I run AutoHotkey V1.1 and the yet-to-be-release V2.0 simultaneously using the techniques discussed in an earlier blog.)
Continue reading

Beginning Tips for Writing AutoHotkey Scripts

Exploring the Existential Mysteries of AutoHotkey Code and How It’s Often Misunderstood

AutoHotkeyInsightsI’ve just published my latest book, Beginning Tips for Writing AutoHotkey Script, which endeavors to clear up some of the mystery surrounding the way AutoHotkey works. You’ll find grasping how AutoHotkey processes AHK scripts a tremendous help. Quite a bit of the confusion encountered by novice AutoHotkey scriptwriters occurs through misunderstandings about the manner in which everything (life, the universe, and AutoHotkey scripts) fits together. I wrote the book with that muddiness in mind. Continue reading

Using Associative Arrays to Solve the Instant Hotkey Data Recall Problem (AutoHotkey Technique)

While Many Other Approaches Work (Sort of), AutoHotkey Associative Arrays Provides a Simple Solution

Elegant Solution

Refinement and simplicity are implied, rather than fussiness, or ostentation. An elegant solution, often referred to in relation to problems in disciplines such as mathematics, engineering, and programming, is one in which the maximum desired effect is achieved with the smallest or simplest effort.

In the last few blogs, I figured out a number of solutions for returning the insertion text via Hotkey combinations for multiple GUIs in the InstantHotkey.ahk script. Many of these approaches worked, yet I continued searching for a more elegant answer. Now, I present my best solution (so far) which includes the use of an AutoHotkey associative array. Continue reading