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

Advertisements

Matching Instant Hotkeys with a Loop (AutoHotkey Tip)

Sometimes You’ll Find a Loop a Simpler Way to Match Things

ProgrammingRobot

“…stuck in an infinite loop. Like I just said, it’s so depressing to get stuck in an infinite loop. Like I just said, it’s…”

If you’re new to AutoHotkey with little or no scripting experience, then this blog may venture too far into the weeds. I don’t like to put off new users because the journey into Windows scripting is well worthwhile. Most find it easy to get started with AutoHotkey with many simple-to-implement tools. However, it takes a little time to understand the nuances of the more advanced techniques. I recommend that AutoHotkey noobies start with the basics such as found in the “Introduction to AutoHotkey: A Review and Guide for Beginners” page. You’ll obtain immediate, rewarding results with basic AutoHotkey. Then, as your comfort with scripting increases, introduce yourself to more of AutoHotkey’s power with some of the slightly elevated topics.

*          *          *

In the last blog, by writing the IH_VarText(Var) function, I created a clever (even if I do say so myself) yet uneasy technique for linking the Instant Hotkey combination to the insertion text by converting the key combination (full of illegal variable characters) to a legal two-deep variable. While this worked, in most cases, it left a number of holes in the subroutine. Unless I added a trap line for every possible illegal key (e.g. the semicolon ” ; “ key, the slash ” / ” key, the hyphen ” ‘ ” key, etc), errors might occur. I needed to make a change. Continue reading

How to Write Easy-Merge AutoHotkey Scripts (Technique Example)

These Steps Make Integrating Your Script Into Combo Apps Simple

In my last blog, “Encapsulate AutoHotkey Code for Multi-Script Integration and Portability (Scripting Techniques)“, I explained how to hermetically seal the auto-execute section of a script, then make variable and code object names unique—thereby reducing the risk of conflict within other scripts when building combo apps. By doing this, the script turns into a robust entity easily added to any other .ahk script while continuing to stand on its own as an independent app. As the example for this blog, I’ve rewritten the ScreenDimmer.ahk script. ScreenDimmer(I explain in detail how ScreenDimmer.ahk works in the e-book AutoHotkey Applications—which offers numerous AutoHotkey tips and tricks while reviewing all of the available AutoHotkey GUI (Graphical User Interface) pop-up controls with practical demonstrations of how to use each.) Continue reading

Encapsulate AutoHotkey Code for Multi-Script Integration and Portability (Scripting Techniques)

Run Your AutoHotkey Scripts as Standalone Apps or Add Them Unaltered to Master Scripts by Creating Hermetically Sealed Auto-Execute Modules

If you’re anything like me, you’ve written a number of scripts which you use regularly. You can run each app separately assuring that they don’t conflict but that tends to load the Windows System Tray with too many icons—making it a little difficult to track all of them.

Cover 250 BorderOn the other hand, combining the scripts into a single file presents problems of its own. Any script which contains its own auto-execute section must run this part of the code when it first loads. Simply using the #Include directive won’t do the job. Place it in the top of the file and the other script modules, such as Hotkeys, Hotstrings, and Label subroutines, stop the processing of the original auto-execute section. Yet, if you place the #Include at the bottom, AutoHotkey never sees or runs the new auto-execute section. The novice scriptwriter often solves the problem by breaking apart the script and separately adding the auto-execute section to the top of the master file while locating all the other code modules toward the end of the file.

Continue reading

How AutoHotkey Reads Scripts (AutoHotkey Script Structure)

Understanding the Layout of an AutoHotkey Script Helps When Writing and Debugging Applications

The Problem with AutoHotkey Script Design

If you’re anything like me, then you probably jump straight into writing a script without reading the online documentation. Experienced programmers don’t have much problem with this, although even they occasionally find themselves scratching their heads about a particular piece of code which seemingly gets ignored by AutoHotkey. Continue reading

Automatically Add Windows Shortcuts to the QuickLinks App (AutoHotkey Tip)

Rather than Manually Creating Windows Shortcuts for QuickLinks.ahk, Use the AutoHotkey FileCreateShortcut Command

*          *          *

Recently, while working with the QuickLinks.ahk script, I’ve encountered so many AutoHotkey learning points involving a number of different techniques that I plan to spend the next few blogs discussing the various possibilities. If you regularly use QuickLinks, then you’ll likely want to fashion it to your needs. While most of the tailoring gets done by working directly with the target folders, you’ll find times when changing the code works best. Rather than attempting to deliver a final product for final download, I offer instruction on how to add various features to your version of QuickLinks.ahk and leave the work up to you. The example shown in the image below reflects the changes I’ve made to my personal copy and do not appear in the posted version.

*          *          *

One of the characteristics I like most about the QuickLinks.ahk script is its simplicity. It operates on a basic backbone which includes two loops (the files and folders Loop command). The first loop works through the folders found in the QuickLinks directory creating the top level menu. The second loop adds the individual links in each folder to each main menu item. Continue reading

Reset Hotkeys with Label Name Drop-Through Behavior (AutoHotkey Tip)

Sometimes Not Encapsulating Hotkeys with the Return Command Serves a Purpose

Last time, I discussed how to change the transparency level of any window under the mouse cursor with a scroll of the mouse wheel. The SeeThruWinWheel.ahk works great, but, if you increase the invisibility of the window too much, you might lose track of the window. I needed a method for instantly bringing a faded window back into view. I did that with a trick from the blog “Understanding Label Names and Subroutines (Beginning AutoHotkey Tip).”

AutoHotkey Library Deal
AutoHotkey Library Deal

While studying the behavior of Label names in AutoHotkey scripts, I came up with the CheeseBurgerRecipe.ahk script which automatically moves to the next Hotkey recipe step with no additional code by dropping pass the next Label name directly into its subroutine. I didn’t expect to find another use for this technique so soon, but when I encountered the problem of losing track of invisible windows, this technique offered a quick fix. Continue reading