Why AutoHotkey for Engineers and Scientists?

While Writing AutoHotkey Scripts Should Be No Problem for Most Engineers and Scientist, Many Might Be Surprised by How Much the Free Language Offers in Windows Tools

I’m not sure how many people with technical backgrounds are familiar with AutoHotkey. My guess is that quite a few have never heard of the free open source robotpicartoonlanguage. Without a personal referral or ubiquitous marketing, free software such as AutoHotkey often goes overlooked for a long period of time. It’s not until individuals realize how much AutoHotkey can do for them that they start to explore the possibilities.

No software package does everything you want. That’s why adding little extras makes any program better. The beauty of AutoHotkey is that in addition to automating individual Windows programs, it can cross boundaries and add more features to any Windows software. Plus, it has the capability to create special pop-up apps for specific usages. The Windows utility building features in AutoHotkey can be especially helpful for anyone working in a technical field.

Scientific Terminology and Specialized Calculators

Engineers and scientists will discover many more applications for AutoHotkey than I introduce here. I confine my discussion to two roles for the Windows software: adding mathematical symbols to any documents and creating special purpose calculators and testers. Since most computer keyboards don’t accommodate scientific notation, creating AutoHotkey Hotstrings comes in handy for inserting these characters and symbols into any Windows document or Web page. Plus, the advanced capabilities of AutoHotkey offer tools for building utility calculating and/or testing pop-up apps for specific areas of technical expertise.

Inserting Mathematical and Scientific Symbols

This first discussion outlines the adding of technical notations to any Windows document. Regardless of the engineering or science profession, writing reports, creating designs, and running experiments almost always requires the insertion of special characters and symbols into editing fields. While many word processing programs include special character tools for inserting unusual symbols and the built-in Windows CharMap (press WIN+r 0r microsoft_key+r, type CharMap, click OK ) can make adding unique characters a little easier, AutoHotkey can set up universal Hotstrings for instantly inserting special characters into any Windows editing field without accessing extra menus or searching for the right symbol.

In addition to built-in special character software features and Windows CharMap, other alternatives exist to AutoHotkey Hotstrings. For example, you can access this convenient Web site (http://math.typeit.org/) to create your mathematical expressions. Yet, with AutoHotkey, you can turn each symbol into a Hotstring text replacement which works in any program without any Web lookup.

The TypeIt Web site offers these mathematical symbols for insertion into documents. With AutoHotkey, you can turn each one into a simple text expansion Hotkey which works in any Windows program.

AutoHotkey Hotstring Code

Writing simple one-line AutoHotkey Hotstrings makes each mathematical symbol available on any Windows keyboard. It’s merely a matter of setting up Hotstring combinations which make the most sense to you. Here I offer a few possibilities:

:*:1/4*::¼    ; one-quarter
:*:1/2*::½    ; one-half
:*:3/4*::¾    ; three-quarters
:*?:deg*::°   ; degree
:*:::↔     ; two-direction-arrow
:*?:>->::→    ; right-arrow
:*?:<-<::←    ; left-arrow
:*?:<=>::⇔    ; double-two-direction-arrow
:*?:<=<::⇐    ; double-left-arrow :*:>=>::⇒     ; double-right-arrow
:*:int*::∫    ; integral
:*?c:E1::¹    ; first power
:*?c:E2::²    ; squared
:*?c:E3::³    ; cubed
:*:sum*::∑    ; summation
:*?:+-::±     ; plus or minus
:*?:x*::×     ; multiplication sign
:*?:-|::÷     ; division sign
:*c:F*::ƒ     ; function
:*?:~~::≈     ; approximation
:*?:/=::≠     ; not equal

Embed each special character into the script by merely copying (highlight plus CTRL+C) from any source and pasting (CTRL+V) directly into the script editing program.

While not a complete list (I’ll leave that to you), these Hotstrings demonstrate the possibilities. Each Hotstring combination establishes an activation sequence which is hopefully easy to remember.

*          *          *

AutoHotkey Library Deal
AutoHotkey Library Deal

If AutoHotkey (or any type of script writing) looks like a foreign language, then check out this “Introduction to AutoHotkey: A Review and Guide for Beginners” page.

*          *          *

Each AutoHotkey Hotstring consists of two sets of two colons (::[activating characters]::[replacement text])—all on one line. The beginning set of colons marks the start of the Hotstring, the second set of colons delimits the replacement characters or string. Each line acts as an independent command which can appear almost anywhere in a script—usually toward the end of the script after any setup code.

Options may appear between the first two colons. The * option between the two first two colons tells AutoHotkey to instantly replace the Hotstring without waiting for any other character or punctuation key press. The ? option tells AutoHotkey to execute the replacement even if found in the middle of a word. The c option demands case sensitivity of the activating string.

Once loaded, by merely typing the Hotstring combinations, AutoHotkey returns the special characters as shown:


turns into:

∫ ƒ'(x)dx

I suggest you pick activating Hotstrings which make the most sense to you. That way they will be easy to remember. Of course, you can always create a Hotkey pop-up window with the MsgBox command which reminds you of all the activating Hotstrings.

Special Purpose Calculators and Testers

Depending upon your field, you may need tools for calculating out-of-the-ordinary formulas. For some scenarios, you might use a spreadsheet, such as Microsoft Excel, or you may need to write a high-powered program for more complex testing, but wouldn’t it be nice to use a few simple, quick tools for those unique calculations you need to make every day. You can build them with AutoHotkey.

To demonstrate how to quickly build pop-up tools with AutoHotkey, I wrote a short script for converting temperatures between Fahrenheit, Celsius, and Kelvin. (Since the current Windows 10 calculator offers the same function, I introduce this script for demonstration and educational purposes.)

Temperature Conversion Calculator

tempconvertThis TempCalc.ahk script creates a pop-up window which, depending upon what value changes, instantly converts degrees (°) Fahrenheit, Celsius, and Kelvin to each of the other scales. First, we set up the pop-up using the Gui (Graphical User Interface) command (image shown at right). Second, we embed the conversion formulas in subroutines called gLabels for calculating and updating the alternative scales.

Creating the AutoHotkey Pop-up Window

AutoHotkey contains commands for building pop-up windows. They include a wide variety of controls making them flexible and powerful. While this relatively routine example demonstrates one possibility, you’ll find no limit on the number of ways a technical person can use GUI windows. (For a peek at the various GUI control types and their visual appearance, see “The Use and Images of AutoHotkey GUI Control Popup Windows.”)

Since I’ve written extensively about the Gui command and its various options (particularly in the book AutoHotkey Applications), I only offer a brief overview of the commands and controls here. The following code sets up the pop-up window shown above:

Gui, -MaximizeBox -MinimizeBox

Gui, Add, Text, x15 Center ,Temperature`rConvert
Gui, Add, Edit, x10 vFar gFarChange Right w50, 32
Gui, Add, Text, x+10 , °F
Gui, Add, Edit, x10 vCel gCelChange Right w50, 0
Gui, Add, Text, x+10 , °C
Gui, Add, Edit, x10 vKel gKelChange Right w50, 273
Gui, Add, Text, x+10 , °K

Gui, Show, , Temp

When adding (Gui, Add, …) individual controls (text, edit fields, buttons, etc.), AutoHotkey GUI pop-up windows automatically resize themselves to fit. Each Gui, Add command inserts one control—by default placing them in the GUI window from the top-left corner to the bottom. Special positioning options, such as absolute location (e.g. x10) and relative placement (e.g. x+10), allow precise location of controls within the window. (See GUI positioning options.)

Created simultaneously with the control, the letter v appearing before a text name (e.g. vFar, vCel, and vKel) indicates the assignment of the control’s variable. This variable holds the control’s value.

If the control options list contains any text string preceded with the letter (e.g. gFarChange, gCelChange, and gKelChange), then, depending upon the control, a Goto (gLabel) action subroutine activates when specific events occur. In the case of the Edit control, whenever detecting a change in the field contents (either by keyboard or AutoHotkey script action) the gLabel subroutine fires. Each subroutine label name (the label name followed by a single colon, e.g. FarChange:) which marks the beginning of the target subroutine must exist somewhere in the script when the file first loads.

Calculating Subroutines

AutoHotkey starts each subroutine with the label name (without the preceding g) followed by a single colon. Normally, a subroutine terminates with the Return command and can appear anywhere in the script after the initial setup code (i.e. in this case, they cannot appear within all the Gui command code lines). The following gLabels carry out the calculations needed as each temperature edit field changes, respectively:

FarChange:         ; Fahrenheit change
  ControlGetFocus, OutputVar
  if (OutputVar = "Edit1") {
     Gui, Submit, Nohide
     Cel := (Far - 32)*5/9
     GuiControl, ,Cel, % Round(Cel,0)
     Kel := Cel + 273.16
     GuiControl, ,Kel, % Round(Kel,0)

CelChange:       ; Celsius change
  ControlGetFocus, OutputVar
  if (OutputVar = "Edit2") {
     Gui, Submit, Nohide
     Far := (Cel*9/5)+32
     GuiControl, ,Far, % Round(Far,0)
     Kel := Cel + 273.16
     GuiControl, ,Kel, % Round(Kel,0)

KelChange:        ; Kelvin change
  ControlGetFocus, OutputVar
  if (OutputVar = "Edit3") {
     Gui, Submit, Nohide
     Cel := Kel - 273.16
     GuiControl, ,Cel, % Round(Cel,0)
     Far := (Cel*9/5)+32
     GuiControl, ,Far, % Round(Far,0)

A few features of note appear in each of the three gLabel subroutines above. First, the ControlGetFocus command grabs the name of the active control. AutoHotkey uses this control name to isolate any action with an IF conditional whenever that control has focus. Otherwise, since any change in an edit field (by keyboard or by the script) activates its respective gLabel, all three subroutines would continually fire as they change the other control values.

The routines require the Gui, Submit command to capture the new value of the temperature in the target field.

After calculating the new temperatures, each subroutine uses the GuiControl command to update the other temperature fields. The powerful forced expression operator % immediate evaluates and inserts the value of the Round() function.

Add the following Hotkey routine to the end of the script to recall the TempCalc.ahk window at any time:

  Gui, Show

Press WIN(microsoft_key)+ALT+T to reactivate (Gui, Show) the pop-up.

Power Theory/Testing Tools

The simple temperature conversion calculator may not convince an engineer or scientist of the usefulness of AutoHotkey, but take a look at this next Theory Tester:

Of course, this AutoHotkey pop-up window was fabricated merely for the purpose of demonstrating how a really useful theory testing tool might operate. While it doesn’t actually do anything, it looks important and maybe even scientific in nature. I leave it to you to make it work.

Okay, maybe this one is a total fiction. (I built the pop-up with Rajat’s AutoHotkey SmartGUI Creator, but it is non-functional.) I can only guess how someone might implement these techniques in engineering or science. The work is so varied that it’s up to the AutoHotkey user to determine how to best build the most useful tools.

One thought on “Why AutoHotkey for Engineers and Scientists?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s