New Flexible Hotstring Features Added to AutoHotkey

Last February, AutoHotkey Release 1.1.28.00 Included Important New Hotstring Capabilities

A few months back while working on my latest book, Jack’s Motley Assortment of AutoHotkey Tips, I encountered a new x option for Hotstrings. The x option enables the running of functions and commands rather than replacing text. This new feature surprised me since, in the past, a one-line Hotstring would only do text replacement.

I immediately recognized that this approach to one-line action Hotstrings could immediately shorten a long list of function Hotstrings. However, closer scrutiny of the new AutoHotkey release revealed further (and possibly more important) new Hotstring functionality. In addition to the x option, the February AutoHotkey release includes:

  1. A new Hotstring() function which adds dynamic capabilities to Hotstrings.
  2. A new method for creating function Hotstrings by defining the function immediately after the Hotstring(s).

Continue reading

Advertisements

Save AutoHotkey Script Settings in Your Windows Registry

While You Can Use an External File to Save Your Script Defaults, You Can Also Call-on the Windows Registry to Store App Settings

In most cases, I’ve used a separate file (text or INI) to save settings. While this works well, it requires the creation and tracking of that independent file. For the script to read the settings, it must know where to locate that file. But, if you want to save script settings without the baggage of that extra file, then consider using your Windows Registry.

You’ll find a few advantages to maintaining your script settings in the Windows Registry:

  1. Unlike a separate settings file, you don’t need to keep track of the Windows Registry’s location—it never moves. Regardless of where you locate your AutoHotkey script on your computer, you will always find its settings in the exact same place.
  2. You won’t accidentally lose your settings by manually deleting what may seem like an extra file in Windows File Explorer.
  3. Your settings remain semi-hidden from public view in a semi-permanent form.

This approach to storing your script defaults deep inside the recesses of Windows adds an air of mystery to your apps—especially if you compile them into EXE files. Continue reading

Pressing GUI Buttons with a Single Keystroke (AutoHotkey Tip)

Sometimes We Find It Easier to Hit a Key Rather Than Click a Button

An AutoHotkey forum user posted a question about using Hotkeys to activate buttons in a GUI window. He wanted to hit the numbers 1, 2, 3, or 4, rather than clicking the individual buttons—but only for the active GUI window.

hotkeycover200While I discuss similar isolation of Hotkeys to specific active windows in my Hotkeys book, this blog provided another opportunity to show how to add more functionality to your GUIs without infringing upon other programs or Hotkeys. I attempted to make the script as simple as possible by using a number of AutoHotkey tricks. Continue reading

Wrapping Up the DateStampConvert.ahk Script (AutoHotkey Tips)

In Previous Blogs, I Used Regular Expressions to ID Dates Formats in Documents and Simulated Case/Switch Statements to Convert Month Names to Numbers. Now, I Build the Standard DateTime Stamp, Check for Valid Dates, and Deal with Two-digit Years, Plus Use the Function ByRef Method to Bypass Local Variables.

While in conversations with a reader who uses AutoHotkey to calculate the time span between two dates for figuring out new leases, I realized that a tool which captures formatted dates from any document and converts them into the DateTime Stamp format (yyyymmdd) would make using the HowLongYearsMonthsDays.ahk script even easier. That prompted me to write the DateStampConvert.ahk script. Continue reading

Using Regular Expressions to Convert Most Formatted Dates into DateTime Stamps (AutoHotkey Tool)

AutoHotkey Offers Many Techniques for Converting the DateTime Stamp (yyyymmdd) into Formatted Dates, But What About Going in the Other Direction? Use RegEx to Identify Date Formats!

DateStampThe HowLongYearsMonthsDays.ahk function calculates the difference in years, months, and days between any two dates. To manually set the two dates, the script employs two DateTime GUI controls—input dates saved in the DateTime Stamp format (i.e. yyyymmdd) and the output in years, months and days. But wouldn’t you find it easier if you could highlight the dates in any document or Web page regardless of format, then use AutoHotkey to convert and copy the DateTime Stamps directly into the DateTime GUI controls? Continue reading

Use Gui, +OwnDialogs to Glue Modal Dialogs Boxes to GUI Parent Windows (AutoHotkey Best Practice)

Save Confusion and Annoying Missteps by Creating Child Dialogs

I began working on the promised formatted date to DateTime Stamp conversion blog when I received this question from a reader:

Hi, Jack,

I’ve created a series of pop-up boxes to help me in doing telephone-service. I have two problems, both with InputBox:

  1. How can I put a comma in the prompt section? I tried things like \, and [,] but none work. I’m sure there must be a solution, but I can’t find it in browsing through your books.
  2. It is possible to include an “always on top” control for the display of an InputBox? It does not seem to work to put ”WinSet, AlwaysOnTop, ON, A” before or after an  Inputbox entry. Is there some way to make an Inputbox display automatically stay on top?

Many thanks,

Tim

Continue reading

Swapping Variable Values (Beginning AutoHotkey Tip)

Rather Than Rewriting Code, Sometimes You’ll Find It Easier to Swap Variable Values

You may not need to use this technique very often but when you do, it can save you a lot of time.

Calculating Years, Months, Days Problem

I wrote the HowLong(FromDay,ToDay) function to calculate the difference between two dates in years, months, and days. The way the function operates it starts at the first date (FromDay) and works its way forward to the second date (ToDay). If the first date occurs after the second date, the function yields bad results.

HowLongOriginally, I added a trap to notify the user when the first date occurred after the second date—offering an opportunity to try again. However, I eventually realized that I only needed to reverse order of the dates to yield the right answer. Rather than rewriting a ton of code to create a backward-looking function, I left the original logic untouched by swapping the two date values when in reverse chronological order. Continue reading