How to Neutralize Errant Hotstrings (AutoHotkey Trick)

Take Advantage of Hotstring Precedence to Deactivate Unwanted Hotstrings Firing

Sometimes AutoHotkey Hotstrings fire at the wrong time. For example, whenever I put the word AutoHotkey into a document I prefer the full word rather than an abbreviation (AHK). I use “ahk” as the Hotstring—replacing it with “AutoHotkey” in almost all cases.

However, when I started adding the same extension to my scripts, I would get “IPFind.AutoHotkey” rather than the “IPFind.ahk” that I needed. This was exacerbated by the fact that the preceding dot ( . ) caused a Hotstring reset making some of the usual fixes unavailable. I needed to disable “.ahk” as a Hotstring.

The two requirements for neutralizing an errant Hotstring include:

  1. The new Hotstring must appear in the script before the primary Hotstring. The first form of a Hotstring found in the script takes precedence over any following Hotstrings using the same trigger.

    Note: Hotstring precedence only applies to Hotstrings loaded from the same script. The most recently loaded identical Hotstrings from another script takes precedence over any previously activated Hotstrings.

  2. Reset the Hotstring trigger without any replacement.

The following set of Hotstrings disable auto-replacement whenever preceding the activation term “ahk” with a dot ( . ) while continuing to replace all other lower-case forms of “ahk” with “AutoHotkey”:

:B0C?:.ahk::
:C:ahk::AutoHotkey

When activated, the B0 option prevents backspacing, the C option ensures an all lowercase trigger, and the ? option causes immediate execution. Effectively, the activation makes nothing happen—except resetting the Hotstring trigger. AutoHotkey recognizes “.ahk” and does not replace it. Any other form of all lowercase “ahk” triggers “AutoHotkey” as its replacement.

You’ll find other, more complex methods for dealing with special Hotstring situations but sometimes all you want a Hotstring to do is nothing.

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.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

AutoHotkey Quick Tip: Conditional Hotstrings Using the Input Command

Sometimes the Input Command Solves a Sticky Hotstring Problem

* * *

I promised an associative array tutorial for my next blog, but this topic intervened. I should have the tutorial ready for next Monday.

* * *

Recent comment on my blog “Auto-Capitalize the First Letter of Sentences“:

This routine can be handy, though the main issue is that, in AHK, “if more than one hotstring matches something you type, only the one listed first in the script will take effect”. Actually, I’m not sure about that, as it appears that using the asterisk as a hotstring option takes precedence. In any case, this does seem to have the effect that other hotstrings that could otherwise be used cannot be used if they also match the code provided here. I have lots of those types of hotstrings, which I use on new lines and after punctuation. I have been unable to find any solutions to this since AHK does not accommodate sequential firing.

A short demo:

:T:tn::Thanks
:C*?:`nt::`nT

Run this script. Type “Tn” on a new line. It works to type “Thanks”. Now type “tn” on a new line. The first line in the script is now skipped. You see only “Tn” in response.

Comment On “AutoHotkey Tip of the Week: Auto-Capitalize the First Letter of Sentences” by mikeyww

Whenever a Hotstring fires, it resets and waits for the next Hotstring. Therefore, the firing of the new line character and “t” (`nt) removes the letter “t” from the next string and starts over with the “n” character. The asterisk option (*) does not affect this behavior. It merely causes that Hotstring to fire before the first—then reset—prior to pressing the “n” key. However, I do appreciate the problem.

Continue reading

AutoHotkey Tip of the Week: Repeat Words and Phrases with RegEx Hotstrings

Save Time with This RegEx Hotstring for Inserting Repeated Words or Sentences—”Blah!” Instantly Turns Into  “Blah! Blah! Blah!”

regexrobotcartoonAt the end of my last blog, I postulated the possibility of a word duplicating RegEx Hotstring. While I don’t know how many people would ever use it, I do remember a time when the technique would have come in handy (as shown in the cartoon on the left). I thought that I would leave the problem as a reader’s challenge and move on, but I found that I couldn’t just abandon the loose end.

While this trick may not embody the most essential Hotstring, the technique might stimulate other AutoHotkey users to venture forward with their own variations on RegEx Hotstrings. I would love to hear about other innovative applications of the RegExHotstring() function—doing things that prove difficult (or impossible) with either traditional double-colon Hotstrings or the built-in Hotstring() function. Continue reading

AutoHotkey Tip of the Week: Auto-Capitalize the First Letter of Sentences

Some People Don’t Find It Easy to Shift to Uppercase While Capitalizing Words—AutoHotkey Allows Us to Stop Reaching for the Shift Key—at Least for New Sentences!

I received the following question from a reader:

Hello,

Is there a script to auto-capitalize the first word of a sentence. Or after a period?

Thanks.

*          *          *

Not everyone received an A in typing class—I didn’t. Plus, many people for a variety of reasons may find navigating a keyboard difficult. Where using the Shift key may be a simple inconvenience for some, people who are not blessed with full functioning fingers and/or hands encounter an arduous task. Even capitalizing the word “I” (“i think i will go”) can present a challenge. The primary goal of AutoHotkey is to make your Windows life easier. Continue reading

AutoHotkey Tip of the Week: Flexible AutoHotkey Hotstring Menus Using Arrays

New Parameters for the HotstringMenu() Function Adds Flexibility and Power to Pop-up Menus

In my last blog, I started looking at adding the variadic parameter (accepts multiple inputs) and a Menu subroutine parameter to the HotstringMenu() function. While in the process of creating alternative Label subroutines, I found that changing a subroutine often called for a new menu-creating function. Rather than resorting to multiple functions, I decided to add one more parameter for tailoring the master function.

CoverImage200
A Multitude of AutoHotkey Tips and Tricks

Note: This blog discusses the use of AutoHotkey object-based arrays (simple and associative) with the function’s variadic parameter. A review of my books demonstrated that most included discussions of arrays (pseudo-arrays and object-based arrays). In particular,  Chapter 12.1.5 “Using Associative Arrays to Solve the Instant Hotkey Data Recall Problem” in the book Jack’s Motley Assortment of AutoHotkey Tips explains the difference between the various array types while offering a practical example of an associative array.

Continue reading

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

The Duality of Curly Brackets in Hotstrings (Beginning AutoHotkey Tips)

Curly Brackets {…} in Hotstrings Both Insert Special Features and Neuter Hotkey Modifying Characters—When Properly Used, They Add Flexibility to AutoHotkey Hotstrings

Sometimes you want to do more than simple text replacement with your AutoHotkey Hotstrings. The key to adding those special features lies with embedding either manual keys within curly brackets (i.e. {Left 5}) or adding Hotkey action directly (without curly brackets) such as CTRL+I (^i for italics) or CTRL+B (^b for bold). The fact that the curly brackets {…} behave in two different manners can cause confusion. 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

Use the FileSelectFile Command to Save Instant Hotstrings to an AutoHotkey File

After Taking the Time to Create Hotstrings with the InstantHotstring.ahk Script, It Only Makes Sense to Save the Code to an AutoHotkey File for Future Use

*          *          *

This blog is part of a series of articles discussing how to create instant Hotstrings using the Hotstring() function.

*          *          *

Ultimately, after writing and activating a number of Hotstrings with the InstantHotstrings.ahk script, we want to save them in an AutoHotkey file. That frees us from recreating the set of auto-replacements the next time we need them. Plus, rather than always loading the Hotstrings into the app, we can run the .ahk file directly with AutoHotkey. 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