Capturing Computer Screen Measurements (An AutoHotkey Tool)

Calibrate the MouseMeasure AutoHotkey Tool to Grab Calculated Lengths from Your Computer Monitor

Recently, a reader asked, “Do you think it is conceivable to create a screen ruler in AHK that can be calibrated to my native application ruler. The problem I have now is that I take tons of measurements off the screen and then I have to type that number back into a document. I would love to make a ruler that can basically calibrate with the native app ruler once and make the data from the AHK ruler transfer automatically to the clipboard or better yet straight to the document.”

I responded, “The application you’re looking at is quite conceivable. You can pick coordinates off the screen with the MouseGetPos command and save them. Then you can possibly use two clicks to calculate the difference between the two in pixels then convert it to your scale. There are a number of methods for sending data to documents. It is certainly within the realm of possibilities.”

I then searched the AutoHotkey board only to find that he had already posted the same Ruler question in the “Ask for Help” forum. Fortunately, AutoHotkey Forum user colt had already posted a response. With the heart of the work completed by colt, I decided to add an onscreen calibration method.

Pythagorean Theorem

Pythagoras gave every high school math student a reason to remember his name. He provided the method for calculating the hypotenuse of a right triangle. For most people, the formula fell into the toolbox of things-I’ll-never-do-again. But for anyone who wants to measure distances on a computer screen, the Pythagorean Theorem returns with a vengeance.

Continue reading

Use Alternative Filename Extensions for Special Format Files (Part Five: Finishing AutoHotkey GUI Scripts)

While Changing the Saved Filename Extension in the InstantHotstring.ahk Script Helps Protect Original AutoHotkey Files, the Technique Offers Additional Benefits…Plus, a No-Wait Progress Bar for Instant-Saves

Over the course of the past few blogs, I added protection to files containing AutoHotkey code by both including a one-line file header and changing the saved filename extension to .hsf. These steps have resolved my concern about overwriting any AutoHotkey scripts—from which I may have extracted Hotstrings and loaded them into the “under-construction” InstantHotstringMenuBar.ahk app. At times, I thought that adding the two techniques might be overkill but now I’ve come to realize that using an alternative extension provides benefits that may prove even more useful than my initial attempt at protecting .ahk files.

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

Sensing AutoHotkey Editing Changes for Instant Save (Part Three: Finishing AutoHotkey GUI Scripts)

By Detecting Modifications in Edit Data We Know When to Activate Instant-Save Routines

Any change too active Hotstrings appends an asterisk (*) to the current open filename and enables the Save option.

In the last blog (“GUI Menu Bar “Save” Item Complications (Part Two: Finishing AutoHotkey GUI Scripts)“), I discussed the need to add a special header to a unique type of data file—InstantHotstring generated Hotstrings. This header helps to differentiate between AutoHotkey .ahk files—which you may not want to overwrite—and files generated by the InstantHotstring.ahk script.

When adding a Save option (instant-save using the CTRL+S key combination) to the menu bar, many Windows apps concatenate an asterisk (*) to the file name in the title bar—alerting the user to changes. In this blog, I add a similar change-detecting feature which both displays the appended asterisk and enables an instant-save routine.

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: Word Manipulating Dynamic AutoHotkey Hotstrings

A Mini-Regular Expressions (RegEx) Tutorial Using the RegExHotstrings() Function for Word Swapping and Double Word Auto-Delete

While the RegExHotstrings() function has its limitations (discussed in “Dynamic Regular Expressions (RegEx) for Math Calculating Hotstrings“), we can quickly implement some simple (yet complex) dynamic Hotstrings using a one-line function call. The RegExHotstrings() function offers a few advantages over the traditional Hotstring format. Regular Expressions (RegEx) used in the function bust through the fixed-text limitations of the double-colon format (e.g. ::lol::laugh out loud). RegEx allows you to match string patterns making wildcard text replacements possible. To explain how the RegExHotstrings() function works, I use one-line function calls to replace ambiguous text with targeted results.


In order to make the best use of the RegExHotstrings() function, we need an understanding of the key concepts driving the function. Once we get a hang of how to operate this dynamic Hotstring function, we can analyze the parentheses-enclosed expressions in each example to develop a better grasp of how RegEx works.

In this blog, I highlight two different RegExHotstrings() function word editing operations: one for swapping the order of two errant words; the second for auto-deleting duplicate words. After introducing RegExHotstrings() key concepts, I explain step-by-step how each RegEx behaves.

Continue reading

AutoHotkey Tip of the Week: The Eval() Function for Hotkey Math Calculations and Text Manipulation

The Classic Eval() Function Solves Problems You Didn’t Even Know You Had by Calculating and Resolving AutoHotkey Functions and Expressions Found in Text Strings!

When I work on particular AutoHotkey solutions, often I find myself in the middle of a treasure hunt—picking up hidden gems along the way. Although operative for years, I didn’t know these valuable tools existed until I went searching for answers to a seemingly unrelated problem.

EvalfunctionMsgBox2For example, the simple question about capitalizing sentences led me to the RegExHotstrings() function discussed last time. As I dug deeper into the math-side of dynamic Hotstrings, I discovered the Eval() function. While many old AutoHotkey hands have employed the Eval() function for years, I didn’t understand its power until I used it in the investigation. (Even now the Eval() function does way more than I comprehend. I’ve only scratched the surface of its capabilities.) 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

Quick Tip: Using the Sleep Command with Clipboard Routines

Use the Sleep Command to Debug Intermittent Routines

tipsLast night, I received the following comment from Thom Blake about last week’s blog “Auto-Capitalize the First Letter of Sentences” prompting this Quick Tip about adding the Sleep command at critical points in certain types of AutoHotkey routines:


Great script but I seem to have a problem with the capitalize a word function. It only works intermittently. The message box says “No text selected!” when clearly there is.

Thanks, Thom!

This is a needed reminder about a common problem when using the Send command with the Clipboard routine. Sometimes, for whatever reason, certain commands execute before the completion of the last action. In this case, AutoHotkey attempts to copy text to the Windows Clipboard before the SendInput text selection action completes: 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:


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


*          *          *

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