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

Pass-Through Hotkey Combinations to Prevent Shortcut Blocking (AutoHotkey Tip)

Sometimes You Want AutoHotkey Hotkeys to Block Other Program Shortcuts While Other Times You Want Both to Work

One of the effects of AutoHotkey Hotkeys includes blocking action for key combinations in Windows and other programs. While often desirable, occasionally you want both the Hotkey and the program shortcut to work. To do this we put a squiggle (tilde prefix ~) in front of the Hotkey combination.

In the MouseMeasure.ahk app, use the cursor keys (Right, Left, Up, Down) to move the mouse cursor one pixel at a time for accurate placement of both ends of the graphic measurement line. Delete to clear the line and ToolTip.

When I added the Arrow keys to the MouseMeasure.ahk script as Hotkeys for precisely locating the mouse cursor onscreen, it triggered the undesirable side effect of blocking the text cursor movement associated with those same keys in editing screens. By placing a tilde (~) in front of each Hotkey, I can accomplish both accurate mouse cursor placement in the invisible GUI and continue using text cursor movement in an editing window without disabling or closing the MouseMeasure.ahk app. (See “Replace Hotkeys with the AutoHotkey GetKeyState() Function” for an introduction to the GDIPlus version of the script. See “How to Draw Lines with AutoHotkey Using Windows GDIPlus Graphics” for information on the GDIPlus functions used in the script.)

Continue reading

How to Draw Lines with AutoHotkey Using Windows GDIPlus Graphics

After Laying an Invisible Graphical User Interface (GUI) over Your Computer Screen, You Can Use Windows GDIPlus to Draw Smooth Lines and Shapes

In my last blog (“Replace Hotkeys with the AutoHotkey GetKeyState() Function“), I explained a Hotstring replacement trick as well as introducing GDIPlus graphics drawing functions from an AutoHotkey post by Hellbent. After comparing the functions in the GDIP_All.ahk library with those from Hellbent, I noted that while many were identical, Hellbent added a few more functions which seemed to make the process easier. Although, I haven’t analyzed the details of each function, I have made them work in the MouseMeasure.ahk script. Here I offer an overview to guide you in how to add an invisible GDIPlus graphics drawing overlay to your computer screen.

Since these GDIPlus functions (included in the script) contain the individual DLLCall() functions, they make it easier to implement on-screen graphics without understanding each enigmatic DLL call. A general understanding of how the MouseMeasure.ahk script works with GDIPlus will help you to implement your own AutoHotkey graphics.

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

Drawing Lines on Screens with AutoHotkey (Graphics Tips)

Although a Little Tricky, You Can Add and Manipulate Windows Graphics on Your Computer Screen with AutoHotkey

In the blog “Capturing Computer Screen Measurements (An AutoHotkey Tool)“, I added a calibration method to an on-screen ruler for extracting distances from any image. It works well for capturing straight-line measurement from a computer display. However, when following the mouse cursor, it lacked a discernible tracking line between the start and stop points.

The green line anchors at the start point and moves with the mouse cursor.

With a search, I found an old post about how to generate a line on-screen. I copied the code and turned it into a function for displaying the green line shown in the image above.

Continue reading