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