Automating Web Pages with AutoHotkey

When Automating Tasks, Browser Web Pages Present Special Problems

Due to the nature of the Internet and the function of Web browsers, AutoHotkey users encounter particular issues when automating Web pages. AutoHotkey GUIs (Graphical User Interfaces) and many older Windows programs allow direct access to controls for automation. Newer apps tend to use ribbon menus which usually include accessible Alt+key shortcuts. However, Web browsers contain built-in protections which insulate users and make controlling operations more opaque. The average Web surfer only has access to what appears on the screen. Getting to the inner workings of Web browsers requires special tools.

After receiving a request from a Web browser, the Web server sends code consisting of HTML and JavaScript to that Web browser. The Web browser interprets the code and sends the results to the computer screen in the form of text, images, links, and controls. The Web browser sends back any user actions requiring server action.
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

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

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

AutoHotkey Tip of the Week: Quick Menu for Activating Open Windows

With a Few Modifications, the WindowList.ahk Script Pops Up a Menu of Open Windows for Quick Activation—Plus, How to Detect When a Windows Opens or Closes

I originally used the WindowList.ahk script as a demonstration of how to use the GUI DropDownList control as a list of selection options for activating open windows (included in the Digging Deeper Into AutoHotkey book). Once, while testing someone’s script, it proved very useful. I could not find the GUI window generated by the code. The script had placed the target window somewhere off the screen. The scriptwriter originally used a second monitor—which I didn’t have. The WindowList.ahk script moved the window back into my view.

As I reviewed the script, I realized that building a pop-up menu of open windows could serve a purpose similar to the QuickLinks.ahk script—except, rather than launching apps and Web sites, the menu would activate open windows. Now, that’s something that I can use!

I often keep numerous windows open simultaneously. Generally, I locate a window by hovering over the Windows Taskbar then selecting the image which looks right. It takes a second for the thumbnails to appear, then hovering over each helps me make my selection. But what if I could maintain a menu of all open Windows available in a menu for instant activation? Continue reading

Calculating Timespans in Years, Months, Days in AutoHotkey, Part 2 (Understanding the HowLong() Function)

Taking a Close Look at the HowLong() Function for Calculating Years, Months, and Days

In this blog, I discuss in its entirety the most recent AutoHotkey code for the HowLongYearsMonthsDays.ahk script (introduced in my last blog). I’ve broken it up into snippets in order to explain the purpose of each piece. To get a complete copy of the script check out HowLongYearsMonthsDays.ahk at the “ComputorEdge Free AutoHotkey Scripts” page or for a barebones version (without comments and inactive code) see “Function Calculating Timespan in Years, Months, and Days” at the AutoHotkey Forum. This blog reviews the nuts and bolts of calculating the timespan between two dates.

Continue reading

Turn AutoHotkey System Tray Icons into One-Click Action Buttons (AutoHotkey Tip)

Rather Than Using Hotkey Combinations, a Simple Click of the Icon in the Windows System Tray Launches Your App

One of the features I added to the InstantHotkeyArrays.ahk script turns the Windows System Tray AutoHotkey into a one-click button for launching new Instant Hotkeys. The new hot-button made from an existing icon works out well—especially since I can never remember the Hotkey combination for creating a new Instant Hotkey. Continue reading

Blocking Mouse Action (AutoHotkey BlockInput Tip)

Clarification of Earlier AutoHotkey BlockInput Command Tips

While working on a couple of chapters in my new book, I noticed that I had effectively blocked inadvertent mouse movement while running a demonstration of a Windows Paint automation routine. In the script DrawSquiggle.ahk, AutoHotkey turns off the mouse while it executes various other mouse movements. Otherwise, any accidental manual movement of the mouse cursor might screw up the final result. Most importantly, the command to block mouse action worked without raising user privilege levels or running the script as an administrator.

paintcurvetool
The DrawSquiggle.ahk script demonstrates how AutoHotkey can control the selection of tools and mouse actions in Windows Paint.

Continue reading