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

Finding Tips at Jack’s AutoHotkey Blogs

With Over 300 Blogs, You Might Find It Difficult to Dig Out the One You Need

I launched Jack’s AutoHotkey Blog in 2015. At that time, I had already published a number of AutoHotkey books but I wanted a way to stay in touch with new users and changes in AutoHotkey.

On the right of the Main Menu bar, you’ll find the “AutoHotkey Topics and Series” menu.

Previously, I had published AutoHotkey articles on the old ComputorEdge Magazine site. However, circumstances and expense forced me to take down the database-driven site. Hundreds of my AutoHotkey tips disappeared from the Web. I didn’t want to do it, but times change. (You can find many of those lost tips in the AutoHotkey books available at ComputorEdge E-Books and even more no-longer-published tips—as well as many more recent ideas—in the book A Motley Assortment of AutoHotkey Tips. The major advantage to using the e-books lies in their organization and searchable indexes.)

When I wrote the new articles for Jack’s AutoHotkey Blog, I avoided duplicating the techniques in previously published articles. While a few important techniques rear their heads on multiple occasions (e.g. the Standard AutoHotkey Windows Clipboard Routine), I concentrate on creating practical applications not previously discussed. My biggest fault lies in the fact that I never finish anything.

Continue reading

Turn Web Addresses into Hotlinks for the AHK File Peek Window (AutoHotkey Tip)

Using the AutoHotkey GUI Link Control to Display AHK File Notes Allows You to Turn Web Links Hot

While perusing the notes in various .ahk scripts using the subroutine ReadNotes—which I had added to the AutoStartupControl.ahk script and discussed in my blog “Peeking at Notes Inside Auto-Startup AHK Script Files (AutoHotkey Startup Control)“—I noticed that many scripts included URLs to reference sites. A common practice used by scriptwriters when giving credit to another script or offering additional information about the source, these sites can offer valuable insight or resources. Usually, a Web address appears as a complete URL including the HTTP(S)://. I wondered, “Wouldn’t it be great to just click a link in the Notes window to load the page?”

Since we write AutoHotkey scripts in plain text, attempting to provide hotlinks inside the file using HTML code (or other techniques) doesn’t make much sense. I can open the file and copy the Web address—pasting it into my browser, but a hotlink in the Notes window would save a lot of time. I immediately switched from using the Text GUI control to the Link GUI control. By inserting the Link control into the AutoStartupControl Notes GUI window, I can turn any URL into a hotlink—as long as I use a Regular Expressions (RegEx).

The Link GUI control in the Notes window can turn any fully formed Web address into a hotlink for immediate access.

Using the Link GUI control comes with a couple of foibles, but, for the most part, it behaves in a manner very similar to the Text GUI control.

Continue reading

Create Instant Windows Gadgets Using AutoHotkey Graphical User Pop-ups (GUIs)

One of the Easiest and Quickest Means for Building a Short, Useful PC App Takes Advantage of AutoHotkey GUI Controls—A Review for the Novice Scriptwriter

Many of my sample scripts available at the Free ComputorEdge AutoHotkey Scripts page use the built-in Graphical User Interface (GUI) tools available in the Windows operating system. Taking advantage of these Windows mechanisms demonstrate only one of the many reasons why the free AutoHotkey scripting language affords so much power. With a few lines of code, you can build Windows gizmos for an innumerable variety of applications. The GUI pop-up acts as the primary core for many AutoHotkey scripts. Easy-to-use and only requiring a minimum amount of programming, the GUI makes possible Windows gadgets for almost any use.

While almost all of my books discuss how to use GUIs in a number of different ways, the book AutoHotkey Applications: Ideas and Tips for Writing Practical AutoHotkey Scripts spends a great deal of time discussing various AutoHotkey Graphical User Interface (GUI) pop-ups with example scripts.

Continue reading

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

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:


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

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

Measure Multiple Line Segments with an AutoHotkey On-Screen Ruler

Taking the MouseMeasure.ahk Script to the Next Level, We Add Multiple Calculations for Going Around Corners

The original MouseMeasure.ahk script captures a single-length in a straight line—as a crow flies. While this works great for many applications, roads and highways generally wind over travel distances. Depending upon where you’re going, this can cause a significant variation in the total calculation. To return a more accurate overall estimate, we must break the measurement line into shorter segments.

Start the measurement with the Ctrl+LButton Hotkey, then click the left mouse button for each new leg of the journey. Press the Shift key to terminate the last leg and display the total distance.

The original form of the MouseMeasure.ahk script only allows for a sole straight line. To add more legs to our journey (at different angles), we must implement AutoHotkey techniques for:

  1. Terminating one segment and starting a new one.
  2. Tracking the position of each segment, its length, and the total distance traveled.
  3. Refreshing the screen to include all past legs as well as the new leg.
  4. Sending multiple saved data items for each leg to documents and forms.
Continue reading

Replace Hotkeys with the AutoHotkey GetKeyState() Function

While Digging into On-Screen Graphic Line Generation, I Discovered a Number of New AutoHotkey Techniques to Add to the MouseMeasure.ahk Distance Capturing Script

Last time, I looked into adding a line drawn on-screen to visually represent a linear measurement (“Drawing Lines on Screens with AutoHotkey“). However, I didn’t feel that the drivers I used presented the result I wanted for the MouseMeasure.ahk script. The line jittered too erratically and I found holding down the left-mouse button while dragging awkward and lacking precision. Therefore, I didn’t post the final product—although I did provide a download for the curious.

I have since drawn upon the expertise of other AutoHotkey Forum users to revise the script and create a much more robust app. The new script includes the following improvements:

  1. Only one Hotkey combination (Ctrl+LButton) activates both the calibration and measuring subroutine.
  2. The script no longer requires holding down the left mouse button while positioning the end point of the measurement. The end-point remains attached to the moving mouse cursor.
  3. The more advanced GDIPlus graphics used to draw the line make the line smoother and more robust.

The MouseMeasure.ahk script now uses Windows GDIPlus graphics to draw a red line between the start and end points of the on-screen ruler. The end point of the line moves with the mouse cursor until pinned with either the Shift or Alt key.

I pulled these improvements from a number of sources.

Continue reading

Quick and Dirty Multi-Line Text Formatting (AutoHotkey Tip)

Formatting Text for Various AutoHotkey Tools Can Get Tedious—Use AutoHotkey Section Continuation to Simplify the Work

In the MouseMeasure.ahk script (discussed last time), I added a pop-up window displaying instructions on how to use the app. I formatted the text with a number of new lines and tabs. Usually, this would have required careful placement of the special escape characters, but not this time.

When adding instructions to a MsgBox, we often resort to adding returns (`r), newlines (`n), and tabs (`t) to create the desired layout. While this works, it often produces perverse effects—especially when using individual line continuation techniques to wrap the code for display purposes. However, AutoHotkey offers an alternative type of code continuation which makes text formatting quick and easy— continuation sections (Method #2).

Continue reading