Finalizing an AutoHotkey Script

While No One Actually Ever Completes an AutoHotkey Script, Some People Get Much Closer Than Others

Last June I started a series of blogs on “Finishing and Polishing AutoHotkey Scripts.” (Ironically, I never finished either the script or the series of blogs.) I wrote six articles aimed at making a script more flexible and user-friendly. Once I had added a menu bar to the GUI window, my chosen menu items provided a map to the ultimate finished product. In the course of that work, I introduced a number of methods for enhancing the program.

Continue reading

AutoHotkey Tip of the Week: Toggling Features On and Off

While You’ll Find AutoHotkey Offers Many Methods for Turning Things On and Off, This Technique Makes It Easy

ToDoListINIOver the years I’ve used a number of different approaches to changing the state of buttons, checkmarks, and various other aspects of AutoHotkey app. But, as recommended by numerous sources, I prefer a simple variable reset to the opposite state (on/true/1 or off/false/0). The code comes in shorthand form using the logical-not (!) operator:

Toggle := !Toggle

When used in an expression, this form for the logical-not (!) operator switches off to on and on to off. Continue reading

AutoHotkey Tip of the Week—Powerful RegEx Text Search Shorthand (~=)

AutoHotkey Provides an Abbreviated Regular Expression RegExMatch() Operator ( ~= ) for Quick Wildcard Text Matches

Regular Expressions (RegEx) can get confusing, but once understood, they pay tremendous dividends. Acting almost as another programming language, Regular Expressions in AutoHotkey provide a method for accomplishing complex search and/or replacement with only one line of code. While not impossible, doing the same thing without using RegEx often requires complex tricks and many lines of code. In the beginning, learning RegEx many feel daunting but you’ll find it well worth the journey.

Light Bulb!In spite of the initial learning curve, you don’t need to learn how the two primary AutoHotkey RegEx functions work (RegExMatch() and RegExReplace()) to make good use of a RegEx. The shorthand RegEx operator ( ~= ) provides a method for doing a complex string match without the limitations of the InStr() function. Regular Expressions search for patterns while the InStr() function searches for exact strings.

Continue reading

When to Rewrite Your AutoHotkey Scripts

AutoHotkey Scripting Philosophy or Speeding Up the InstantHotstring.ahk script

“Before you can fix a problem you must understand it. Before you can understand a problem you must fix it.”

Sounds like a chicken/egg problem, but I assure you it isn’t. You only begin to understand a problem when you start working on a solution. As you grind through a script, you develop a deep awareness of its inner workings. I encourage any AutoHotkey novice to jump into a new script with both feet—even if you don’t think you know what you’re doing.

Sitting around and speculating about possible answers to a question often serves as mental thumb-twiddling. You must start somewhere—anywhere. Until you actually dig into it and undertake the work, you will never truly comprehend the obstacles and pitfalls associated with implementing a fix. You’ll find this singularly true when writing AutoHotkey scripts— especially as a beginner. The answer to the question “Where do I start?” is “Anywhere!” Continue reading

Fixed the InstantHotstring.ahk Script Slow Hotstring Loading Problem

New Version of InstantHotstring.ahk Script Now Available!

I’ve rewritten the LoadHotstrings subroutine in the InstantHotstring.ahk script (alternate download) to overcome the slowdown created by using the pre-existing routines found in the original script, “AutoHotkey Script Speed Problems (Scripting Insights).” I simplified things by limiting the subroutine to:

  1. Adding Hotstrings directly from the file without extra processing—no interaction with the DropDownList GUI control.)
  2. Checking for duplicated or changed Hotstrings within a single variable.
  3. Activating each Hotstring as its added.

AutoHotkey exports the DropDownList GUI control contents just once into a single variable and only writes the new DropDownList after processing the entire target file. The test file of over 1000 Hotstrings loads in one to two seconds—depending upon the weather. (The old routine could take up to 70 seconds for that same file.)

You can find the new code (InstantHotstring(FastLoad).ahk) and the old code (InstantHotstring(SlowLoad).ahk) at the InstantHotstring.ahk section of the ComputorEdge Free AutoHotkey Scripts page.

I’m currently working on blogs which discuss both the philosophical and technical aspect of rewriting the subroutine.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)

jack

This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Loading Hotstrings into the InstantHotstring.ahk Script from Any AutoHotkey (.ahk) File

Reading Data from Saved .AHK Files Makes Loading Hotstrings into the InstantHotstring.ahk Script Easy

In the blog, “Use the FileSelectFile Command to Save Instant Hotstrings to an AutoHotkey File.” I discussed how to save a set of newly created InstantHotstring.ahk Hotstrings in .ahk files. The other half of the file storage problem involves reading those saved (or any other) Hotstring data files back into that same app. Using the tools already built into the script made writing the file loading code remarkably easy. The subroutine LoadHotstrings calls on the previously written subroutines SetOptions and AddHotstring. This saves replicating of code originally used in those subroutines.

Continue reading

Dealing with Hash Marks (#) in Hotstrings (AutoHotkey Quick Tip)

When Using the Pound Sign (#) in Hotstring Replacement Text, We Must Take Special Steps to Prevent It from Going Missing…I Mean Disappearing

RobotHashtagCartoonSome would say that we should call the # character an octothorpe. Others insist upon using it in place of the pound weight (# not £). You’ll commonly find it used as the number sign—as in apartment #205 or #2 pencil. Editors use # to tell whomever to add space between two words. In some computer languages, the # sign precedes comments. In Web URLs, the # indicates a “jump to” link within the same page. On Twitter, people insert # to precede topic references as a hashtag (#jellybeans). (People often use the term “hashtag” to show off their technological smarts—#sarcasm.) In AutoHotkey, we use the # symbol as the Hotkey modifying character for the Windows key (microsoft_key). Continue reading

Limit the Number of Substrings Delivered by the StrSplit() Function (AutoHotkey Quick Tip)

A New Parameter in the AutoHotkey StrSplit() Function Makes Selective Parsing Possible

robotparse.pngAt the same time as when we saw the release of the new Hotstring() function and other added Hotstring features (AutoHotkey version 1.1.28.00 – February 11, 2018), the powers-that-be made a significant change to the StrSplit() function. I don’t know if the idea grew from the need to parse Hotstrings or just happened to coincide with that release of AutoHotkey.

I discovered the new power when I ran into trouble working with the InstantHotstring.ahk script while using a Web address as replacement text. This useful new StrSplit() parameter (MaxParts) might save you from adding more code when you need to limit the number of produced pieces of text. (Don’t believe it when they say, “Parts is parts!”)

Continue reading

Add Action to Your Hotstrings Using the New X Option (AutoHotkey Tip)

The Hotstring X Option Offers More Power by Running Commands, Functions, and Subroutines, Plus How to Temporarily Block External Hotstrings

In February of last year, the powers-that-be added a new Hotstring() function and a number of other Hotstring related features (See “New Flexible Hotstring Features Added to AutoHotkey.”) This major change added a host of new possibilities for creating and manipulating Hotstrings. The Hotstring() function acted as the impetus for my InstantHotstring.ahk script. In the process of writing that app, I developed a better understanding of how to enhance Hotstrings. Getting immediate feedback when implementing new replacements and options allowed me to quickly investigate many possibilities. Continue reading

Beginning Hotstring Tricks for Expanding Acronyms (AutoHotkey Tips)

Hotstring Techniques for Expanding Abbreviations Only When You Need Them, Plus How to Sound British…Sort Of

One benefit I’ve discovered when using my InstantHotstring.ahk script includes quickly checking the effects of the various Hotstring options. Without re-editing and reloading an AutoHotkey script, I can test the assorted options and see how they modify the behavior of each Hotstring. This helps me understand how to solve some Hotstring problems. Continue reading