Sending Multiple Saved Data Items to Documents and Forms in AutoHotkey (Temporary Hotkeys)

Sometimes We Want Single-key Hotkeys to Work Only for Short Periods of Time

The press of a single key provides the easiest method for inserting data into an edit field or document. In AutoHotkey, you can activate any key as that quick action single-key with either a Hotkey or Hotstring. However, in the normal course of work, that technique renders that keyboard action useless for anything else. To get the convenience of one-key instant activation, we must activate that Hotkey when needed—only in specific circumstances and for short periods of time.

AutoHotkey offers a number of different methods for accomplishing this instant key action. Which we choose depends upon what we want to do. In this blog, I look at three different methods:

  1. Use the Hotkey command to temporarily turn Hotkeys on then off again.
  2. Use the #If directive to designate conditional Hotkeys.
  3. Temporarily pause the script after Hotkey activation, then deactivate Hotkeys upon resuming.

While each temporary Hotkey works in a similar manner—activating only when needed—each has its advantages and disadvantages.

Continue reading

Track Graphic Line Measurement Segments Using AutoHotkey Arrays

When Refreshing the MouseMeasure.ahk Invisible GUI Graphics Layer, AutoHotkey Uses a Simple Array of Associative Arrays to Track the Data

In my last blog (“Measure Multiple Line Segments with an AutoHotkey On-Screen Ruler“), I introduced multi-segment lines for estimating distances of non-linear routes. When refreshing the graphics to animate the moving line, all previously fixed segments need redrawing. Objects-based arrays provide the best method for tracking and regenerating these lines.

Each leg of the journey corresponds to a simple array element containing an associative array of data. The white box displays the key:value data saved in MyArray[4].

The difference between pseudo-arrays, simple arrays, and associative arrays can get confusing. For the novice AutoHotkey scriptwriter, unfamiliar Object-Oriented Programming (OOP) notation can make understanding the code even more difficult—especially if you attempt to learn OOP from online documentation.

You may think you need to choose between the traditional AutoHotkey syntax and OOP coding, but you don’t! AutoHotkey allows you to mix-and-match most OOP and classic AutoHotkey syntax—as long as you understand how they integrate.

Continue reading

Use the GoTo Command to Traverse Long Subroutines (Part Four: Finishing AutoHotkey GUI Scripts)

Sometimes the GoTo Command Makes Life Easier without Creating Perverse Effects

This next portion of the InstantHotstring.ahk menubar implementation did not go as I had expected. I thought that I would break up the routine launched by the Save Hotstrings button into separate subroutines or functions, then call each as appropriate for the corresponding Save/Append Hotstrings menu items (as seen in the image). I didn’t look forward to it because I knew it could get a little confusing. Some items would require multiple subroutine calls while others would need to just run—depending upon the menu selections made by the user.

I didn’t want to write redundant subroutines, but separating the various features of the complete routine required more than merely adding Return commands to encapsulate the code. I finally ask myself, “Why not insert AutoHotkey Labels into the main Save routine and use the GoTo command to jump my way through the decision points?”

Continue reading

AutoHotkey Tip of the Week: Cramming a Multitude of Controls into a GUI

AutoHotkey GUI (Graphical User Interface) Controls Gives Us Powerful Tools for Building Apps, But Sometimes We Need to Get Creative to Solve the Space Problem


My book AutoHotkey Applications: Ideas and Tips for Writing Practical AutoHotkey Scripts introduces the various GUI (Graphical User Interface) Controls available in the Windows operating system. I offer practical examples of how you can use single controls in a script. Yet each GUI control comes with its own particular limitations. Sometimes it takes a combination of techniques to get the full benefit from a unique control feature.

For example, you may find it a challenge to pack a multitude of items into a single GUI without expanding it beyond the screen. Many controls such as an Edit and ListView control allow you to limit the size of the control—then add scrollbars when the volume exceeds the confines of the space. Not so for AutoHotkey GUI Link controls.

In my last blog, “Cull Web Links from a Web Page and Activate Each in a Pop-up GUI“, I built a GUI pop-up window listing the external links scraped from a Web page (WebLinkFindURL.ahk script). In some cases, the number of links far exceeded the space allowed on my computer screen. Since the GUI Link control does not support scrollbars, I added Tab controls to expand the available GUI space without overwhelming the screen. Continue reading

AutoHotkey Tip of the Week: Dynamic Regular Expressions (RegEx) for Math Calculating Hotstrings

An AutoHotkey Classic, the Dynamic Hotstrings() Function Makes Instant RegEx Replacements Possible—Now, You Can Do Math with Your Hotstrings!

Anyone who reads my blog on a routine basis knows how I love Regular Expressions (RegEx). They make feasible all kinds of capabilities not practical by any other method. While not necessarily easy for a beginner to grasp, RegEx provides a mechanism for matching text when you don’t know exactly which characters you need (wildcards). (That’s why I wrote the book A Beginner’s Guide to Using Regular Expressions in AutoHotkey.) Although you may encounter a bit of a learning curve, RegEx gives you the ability to accomplish some pretty fancy tasks. This time I plan to demonstrate a couple of Hotstring techniques that might amaze you—they did me! Continue reading

AutoHotkey Tip of The Week: Evaluating Deprecated AutoHotkey Commands

As Time Passes, You May Notice More and More Deprecated AutoHotkey Commands in the Online Documentation—When Should You Rewrite Your Scripts and When Should You Ignore the Changes?

While working on the latest version of the QuickLinks.ahk script, I saw that the syntax for the Loop (files & folders) command for the reading the names of directories and files had changed in the online AutoHotkey documentation. (It’s about time that I noticed since it changed back in 2015.) In the original program I used:

Loop, C:\Users\%A_UserName%\QuickLinks\*.*, 2 , 0


Loop, %A_LoopFileFullPath%\*.*, 1 , 0

The powers-that-be deprecated that form of the command substituting:

Loop, Files, C:\Users\%A_UserName%\QuickLinks\*.*, D


Loop, Files, %A_LoopFileFullPath%\*.*, FD

While the new syntax seems a little clearer, it appears to act in the same manner as the original (still operational) form of the command. A person may ask, “Why the change the command at all?” Continue reading

How to Use the Windows Registry to Save Data Table Records

Saving To-Do List Data Items in the Windows Registry Allows Interactive Realtime Updates from the GUI ListView Control


The GUI ListView control acts like a data table (i.e. interactive rows and columns). The ListView control includes a number of functions for adding, inserting, modifying and deleting rows and columns,—plus, even more functions for sorting and selecting rows, as well as, retrieving data. I’ve used the AutoHotkey ListView control for a to-do list (shown at right), an address book,  a calorie counting app and listings of icon images embedded in files. (I consider all of these apps educational tools or starting points for AutoHotkey scripting—not final products.)

The AutoHotkey ListView control operates in the same manner as Windows File Explorer—automatically sorting on clicked column headers with editing available in the first field of the selected row on a second click. When included in a GUI (Graphical User Interface), the control adds a great deal of flexibility to any data table display, but it does not automatically save the data. You must write that code yourself. Continue reading

AutoHotkey Tip of the Week: Increase the Flexibility of Menus by Passing Data with the BoundFunc Object

Streamline and Add Power to Hotstring Menus by Binding Action Parameters Directly to Each Menu Item

*          *          *

If you use AutoHotkey menus, then you may find this blog the most useful menu tip yet. At first, using the BoundFunc Object to pass data may seem confusing, but, once understood, it opens up many more opportunities for taking advantage of menus in your AutoHotkey scripts.

*          *          *


As often happens when working on an AutoHotkey script, a deeper understanding of the available tools completely changes the direction of the project. While all of the Menu tricks I’ve offered in the past HotstringMenu.ahk scripts still work (and you may want to continue using many of those techniques), the following approach which combines arrays, the variadic function parameter, and the boundfunc object creates a cleaner, more functional structure for generating Hotstring replacement menus. In short, implementing the boundfunc object allows me to drop many of those previous menu tricks and build menus using virtually any menu item format without regard for their later use through the value of the A_ThisMenuItem variable.

Continue reading

AutoHotkey Tip of the Week: Use the Variadic Function Parameter for an Unknown Number of Values in Hotstring Menus

What To Do When You Don’t Know How Many Values You Will Use? For Hotstring Menus, the Variadic Function Parameter Allows a Variable Number of Arguments or Direct Array Input

Variadic Function: One which accepts a variable number of arguments.

MenuEmojiTagsLight Bulb!In the blog, “AutoHotkey Tip of the Week: Hotstring Menu Techniques for Inserting Symbols and Emojis“, I discussed switching from the deprecated StringSplit command to  StrSplit() function before posting the scriptAfter posting my new HotstringMenu.ahk script on the AutoHotkey forum, I received the following comment from the user Delta Pythagorean. I have mixed feelings about the recommended changes:

You can simplify this down by making the parameter variadic and letting the user chose which label to set the menu to work off of.

:x:brb::HotStringMenu("MenuLabel","Hello",,"Goodbye","See you later!")

  MsgBox, % "You said: " A_ThisMenuItem

HotstringMenu(Handle, TextList*) {
  For Each, Item in TextList
    Menu, MyMenu, Add, % Item, % (Item != "") ? Handle : ""
  Menu, MyMenu, Show
  Menu, MyMenu, DeleteAll

I like the overall concept. This change to the HotstringMenu() function expands its capabilities by adding a selectable subroutine Label name and uses a variadic parameter which allows the functions to accept an unknown number of values. Continue reading

AutoHotkey Tip of the Week: Add Single-Key Shortcuts to Pop-up Menus—September 16, 2019

Sometimes It’s Just Easier to Use the Keyboard Rather Than Your Mouse

HotString Pop-upIf a menu busts in while typing, it forces you to switch to your mouse for resolution. This can get pretty annoying if your script uses a number of pop-up menus. For example, Chapter Eight, “Make Your Own Text AutoCorrect Hotstring Pop-up Menus with AutoHotkey” and Chapter Nine, “How to Turn AutoHotkey Hotstring AutoCorrect Pop-up Menus into a Function” of the book Beginning AutoHotkey Hotstrings shows you how to set up a list of alternative corrections. It works well for offering options but, at times, wouldn’t you prefer to hit a single key to make the selection rather than first fetching the mouse, then clicking?

Recent Question from a Reader:

Is there any way to improve the script in order to, once the menu appears, select an option using a given key combination?

For instance: If I typed “alt+1” AutoHotkey would automatically select the option “again”, if I typed “alt+2” it would select the option “a gin” and so on so forth until alt+0?

*          *          *
Continue reading