AutoHotkey scripts for writing technical documentation (free)

The open-source automation tool AutoHotkey can be a huge help when creating technical documentation (and not just for that). On this page, you can find some small scripts that I use myself every day in my work and that I would never want to do without. Unlike macros in Word, for example, AutoHotkey scripts work in any Windows program.

You can easily copy all scripts, customize them if needed, and use them yourself free of charge.

What the scripts presented here can do

enter words or entire sentences and paragraphs using keyboard shortcuts

enter special characters using keyboard shortcuts or character combinations

automatically correct typos or automatically replace certain words with other words as you type

disable the Caps Lock key, which is often activated unintentionally

paste text from the clipboard as plain text conveniently everywhere

search for selected words on the web with a push of a button — for example on Google, on another search engine, in an online dictionary, or ...)

You do not need any programming skills to use the scripts. Just copy the code snippets shown and start saving lots of time. But maybe you will get a taste for it and find even more applications for yourself. The possibilities are endless. At the extreme, you can use AutoHotkey to automate entire processes and retrofit things in programs that normally don't work with the program at all.

 

Important: Like any computer program, scripts perform actions on your computer. In some cases, these actions cannot be undone. Save your data before using new scripts. Test new scripts carefully. All information on this page is given without guarantee. The use of the presented scripts is at your own risk.

Preparation: Installing AutoHotkey

For the scripts to run on your computer, you need AutoHotkey as a so-called Interpreter or Compiler. You can download the installation file from the AutoHotkey website at https://www.autohotkey.com.

 

Important: The scripts I present here require version 2.x of AutoHotkey. If you still want to use old scripts written for version 1.x in parallel, when running these scripts, AutoHotkey offers you an option to run them still with version 1 of the interpreter.

→ After installation, the AutoHotkey Dash window appears. Here you can open the AutoHotkey documentation, change settings, and create new scripts.

Basics: Creating and running a script

To use the scripts I present on this page and to slightly modify them if needed, you don't need to know much about AutoHotkey.

Creating a script

1If the AutoHotkey Dash window is no longer open: Start AutoHotkey from the Windows Start menu.

→ The AutoHotkey Dash window appears.

2In the AutoHotkey Dash window, click New script and create a new script file.

→ AutoHotkey creates the file and automatically opens the folder where the file was created.

3Right-click the file (*.ahk) and select Edit script from the context menu.

Note: Along with AutoHotkey, an editor specially adapted for AutoHotkey scripts was installed in its installation directory: The program SciTE4AutoHotkey. This editor provides syntax highlighting specifically for AutoHotkey as well as various other handy features specifically for AutoHotkey. However, you can also use any other text editor capable of writing UTF-8 encoded files, such as Notepad++ (also open source).

 

Important: As of 01/2023, the SciTE4AutoHotkey editor does not yet work in all cases with the new version 2.x of AutoHotkey. In case you get an error message, you can use for example Notepad++ to edit your scripts.

4In the editor, make sure that the file uses UTF-8 encoding with BOM. Else, special characters in scripts will not work properly. In SciTE4AutoHotkey select File > Encoding > UTF-8 with BOM. In Notepad++ you can find the same setting under Encoding > Encode in UTF-8-BOM.

Running a script

Once you have created and saved a script in the editor, you can start the script:

> Double-click the script file. (Alternatively, right-click the script file, and then choose Run script from the context menu).

→ An AutoHotkey icon appears in the notification area of the Windows taskbar.

For most scripts, nothing seems to happen for the time being. The script waits in the background for an event defined in the script, such as the pressing of a certain key combination or the input of a certain sequence of characters. Only then will a function linked to the respective event become active.

Note: Optionally, you can also convert a script into an executable file (“compile” the script). After that, you or other persons can then use this script on computers on which AutoHotkey is not installed. See the corresponding function in the AutoHotkey Dash window and in the AutoHotkey documentation.

Stopping a script

You can pause or completely terminate an active script at any time:

1In the Windows taskbar, right-click the icon of the running script.

2In the context menu, choose:

Suspend hotkeys to disable only the triggers defined in the script, but leave other functions that may exist in the script active

Pause Script to halt the script completely

Exit to terminate the script completely

Tip: In the context menu, there also is a Reload Script command, which you can use to reload a running script at any time. This is necessary if you have made changes to the script file of a running script and want AutoHotkey to apply changes from now on.

Enter words or phrases using keyboard shortcuts

The most basic and at the same time the most important function in AutoHotkey is to trigger something by keyboard shortcut. This enables you to use AutoHotkey, for example, to enter particular frequently used words or phrases using keyboard shortcuts.

Example: You typically have to type the name of the product described in your documentation very often. You can create the following small script for this purpose:

Note: Any characters following a semicolon in a line of code are a comment and will be ignored by AutoHotkey when executing the script.


;--------------------------------------------------------------------
; Autotext
;--------------------------------------------------------------------
#p::SendInput "MyProduct"

From now on, once you have started the script, all you need to do is press the Windows key together with the letter p, and AutoHotkey will enter the name of your product for you as if by magic – the text MyProduct in the example.

Customize hotkey

The syntax #p:: specifies the hotkey. You can easily change the key combination as needed. The following examples show the principle.

Note: [Win] stands for the Windows key, which is usually located between the Ctrl key and the Alt key in the lower left section of the keyboard.

Code

Triggered by key combination

#p::SendInput "MyProduct"

[Win]+[p]

^p::SendInput "MyProduct"

[Ctrl]+[p]

!p::SendInput "MyProduct"

[Alt]+[p]

^#p::SendInput "MyProduct"

[Ctrl]+[Win]+[p]

^+p::SendInput "MyProduct"

[Ctrl]+[Shift]+[p]

!+p::SendInput "MyProduct"

[Alt]+[Shift]+[p]

^F3::SendInput "MyProduct"

[Ctrl]+[F3]

If needed, you can find more codes in the very detailed online help for AutoHotkey (look for “Hotkeys”).

Add more hotkeys

You can add as many additional commands to the script file as you like. The following example, for instance, contains another keyboard shortcut for your name:


;--------------------------------------------------------------------
; Autotext
;--------------------------------------------------------------------
#p::SendInput "MyProduct"
#n::SendInput "MyName"

 

Important: After changing the script, do not forget that a script that is already active must be reloaded after saving for the changes to become effective.

Enter special characters

Just as for text, you can use keyboard shortcuts to insert special characters that you don't find on your keyboard but need frequently. As an alternative to keyboard shortcuts, you can also use certain character combinations as a trigger.

The following script combines both methods.


;--------------------------------------------------------------------
; Typographically correct special characters
;--------------------------------------------------------------------
#a::Send "’"          ; apostrophe
#n::Send "–"          ; en dash (German: Halbgeviertstrich / Gedankenstrich)
#m::Send "—"          ; em dash (German: Geviertstrich)
#i::Send "−"          ; minus sign
#x::Send "×"          ; multiplication symbol
:?*:...::…            ; ellipsis character
:*:""::“”{left}       ; curly double quotation marks English
:*:''::‘’{left}       ; curly single quotation marks English
:*:d""::„“{left}      ; curly double quotation marks German
:*:d''::‚‘{left}      ; curly single quotation marks German

With this script you can conveniently enter the following special characters:

Trigger

Function

[Win]+[a]

typographically correct apostrophe

[Win]+[n]

en dash

[Win]+[m]

em dash

[Win]+[i]

typographically correct minus sign

[Win]+[x]

typographically correct multiplication sign

three dots entered in a row

typographically correct ellipsis

two straight double quotes entered one after the other

two typographically correct (“curly”) double quotes; the cursor automatically moves one position left so that it is between these two characters

two straight single quotes entered one after the other

two typographically correct (“curly”) single quotes; the cursor automatically moves one position left so that is between these two characters

letter d followed by two straight double quotes

two typographically correct (“curly”) quotes German style; the cursor automatically moves one position left so that it is between these two characters

letter d followed by two straight single quotes

two typographically correct (“curly”) single quotes German style; the cursor automatically moves one position left so that is between these two characters

 

Important: Make sure that the script file is saved with the encoding “UTF-8 with BOM”. Otherwise, you will get the wrong or no special characters.

Replace text as you type

A meaningful sequence of letters is often easier to remember than a keyboard shortcut. For example, you could use the string “pe” (followed by a space character or punctuation mark) to enter the text “Professional Edition”. Similarly, “se” could be used for “Standard Edition”.

Maybe there are certain words that you always misspell. For example, if you often forget a “c” in the word “acess”, why not define a script that automatically replaces the incorrect spelling with the correct one always and everywhere?

The script may then look like this:


;--------------------------------------------------------------------
; Auto replacements
;--------------------------------------------------------------------
::pe::Professional Edition
::se::Standard Edition
::acess::access

If you enter “pe” followed by a space character after activating this script, the text “Professional Edition” appears automatically. Similarly, “se” automatically becomes “Standard Edition”. If you misspell the word “acess”, it is automatically changed to the correct spelling “access”.

 

Important: With automatic replacements, always use only such character combinations as triggers that do not make sense as a single word or as an abbreviation. Otherwise, AutoHotkey replaces these instances as well.

Disable the Caps Lock key

Do you sometimes accidentally hit the Caps Lock key and then coNTINUE WRITING WITH CAPITAL LETTERS? Two lines of code in AutoHotkey, and this will never happen again.


;--------------------------------------------------------------------
; Caps lock key deactivation
;--------------------------------------------------------------------
SetCapsLockState "off"      ;sets the caps lock state to OFF
Capslock::Shift             ;maps the Caps Lock key to the Shift key

The Caps Lock key now works as a simple additional Shift key :-)

Paste text as plain text

Not all programs have a user-friendly function to paste text from the clipboard into a document as plain text without formatting. AutoHotkey can do this job well.

With the following script, you can paste text as plain text consistently in all programs with the key combination [Ctrl]+[Win]+[t].


;--------------------------------------------------------------------
; Paste as text
;--------------------------------------------------------------------
^#t:: {
 A_Clipboard := A_Clipboard
 Send "^v"
}

Always keep a window on top

When documenting a window, it can be convenient if this window does not repeatedly disappear behind other windows, but remains visible. Or you may want to use a file with input, a dictionary, or some small utility in parallel with writing. Here, too, for saving space, for example, you may not want to move the window next to your editor or bring it back manually to the foreground again and again.

With the following script, you can change any window so that it always remains the topmost window and thus always visible.


;--------------------------------------------------------------------
; Stay on top
;--------------------------------------------------------------------
^#a:: {
 Title:=WinGetTitle("A")
 ExStyle:=WinGetExStyle("A")
 IF (ExStyle & 0x8)
  {WinSetAlwaysOnTop false, "A"
   MsgBox "No longer set to stay on top: " Title, "Stay on Top Script", "4096"
  }
 ELSE
  {WinSetAlwaysOnTop true, "A"
   MsgBox "Now set to stay on top: " Title, "Stay on Top Script", "4096"
  }
}

To give any open window the property "Stay on Top", activate the window, and then press the key combination [Ctrl]+[Win]+[a].

To restore the window to its normal state later, repeat the operation.

Find selected words on the web

AutoHotkey is also handy for research. With the following scripts you can, for example, copy selected text from any program to a website for search, such as to Google, Bing, or Wikipedia.

1Select the text.

2Press the key combination [Ctrl]+[Win]+[g].

→ Your web browser opens with the search results in Google.

For a search on Bing, similarly use [Ctrl]+[Win]+[g]. For a search on Wikipedia, use [Ctrl]+[Win]+[w].

The scripts used for this look like this:


;--------------------------------------------------------------------
; Web look-up
;--------------------------------------------------------------------
^#g:: {
 ClipSaved := ClipboardAll()
 SendInput "^c"
 sleep 500
 searchterm := A_Clipboard
 Run "http://www.google.com/search?&q=" searchterm
 A_Clipboard := ClipSaved
 ClipSaved := ""
}
^#b:: {
 ClipSaved := ClipboardAll()
 SendInput "^c"
 sleep 500
 searchterm := A_Clipboard
 Run "http://www.bing.com/search?&q=" searchterm
 A_Clipboard := ClipSaved
 ClipSaved := ""
}
^#w:: {
 ClipSaved := ClipboardAll()
 SendInput "^c"
 sleep 500
 searchterm := A_Clipboard
 Run "https://wikipedia.org/wiki/" searchterm
 A_Clipboard := ClipSaved
 ClipSaved := ""
}

The nice thing about AutoHotkey is that you can very easily customize these searches even to very specific websites for which there are no comparable ready-made utilities. For example, to a special online dictionary or terminology database.

You just need to take a close look at where the word(s) you are looking for appear in the address bar of the targeted website. Then adjust the call in the script accordingly.

Tip: In many cases, you can significantly simplify the URL displayed in the browser and omit parameters in it. It may need a bit of experimenting but can well be done even without a degree in computer science.

All scripts in one file

Was there more than one script among the presented ones that you want to use in your daily work? Then you don't need to create and run a separate script file for each function. It is more practical to put all the scripts you need into a single file.

Tip: If you want the scripts in this file to become active automatically when Windows starts, create a shortcut to the script file in the Windows Startup folder.

Enjoy saving time :-)


;###################################################################################################
;
; indoition AutoHotkey Script Collection for Writing Technical Documentation
; Version 2023 for AutoHothey 2.x
; --------------------------------------------------------------------------
; (C) 2023 Marc Achtelig, all rights reserved
;
; To run the scripts, use AtoHotkey Version 2.x, available from http://www.autohotkey.com.
;
;
; USE ALL SCRIPTS WITH CAUTION!
; -----------------------------
; Scripts can interfere with other prorams and might trigger unforeseen actions that result in 
; unwanted changes or loss of data. 
; Back up your data before using a script. Verify your data after using a script.
; All scripts in this collection are provided "as is" with no obligations and with no support.
; Use at your own risk.
;
;;##################################################################################################
;--------------------------------------------------------------------
; Autotext
;--------------------------------------------------------------------
#p::SendInput "MyProduct"
;--------------------------------------------------------------------
; Typographically correct special characters
;--------------------------------------------------------------------
#a::Send "’"          ; apostrophe
#n::Send "–"          ; en dash (German: Halbgeviertstrich / Gedankenstrich)
#m::Send "—"          ; em dash (German: Geviertstrich)
#i::Send "−"          ; minus sign
#x::Send "×"          ; multiplication symbol
:?*:...::…            ; ellipsis character
:*:""::“”{left}       ; curly double quotation marks English
:*:''::‘’{left}       ; curly single quotation marks English
:*:d""::„“{left}      ; curly double quotation marks German
:*:d''::‚‘{left}      ; curly single quotation marks German
;--------------------------------------------------------------------
; Auto replacements
;--------------------------------------------------------------------
::pe::Professional Edition
::se::Standard Edition
::acess::access
;--------------------------------------------------------------------
; Caps lock key deactivation
;--------------------------------------------------------------------
SetCapsLockState "off"      ;turns off the Caps Lock state
Capslock::Shift             ;maps the Caps Lock key to the Shift key
;--------------------------------------------------------------------
; Paste as text
;--------------------------------------------------------------------
^#t:: {
 A_Clipboard := A_Clipboard
 Send "^v"
}
;--------------------------------------------------------------------
; Stay on top
;--------------------------------------------------------------------
^#a:: {
 Title:=WinGetTitle("A")
 ExStyle:=WinGetExStyle("A")
 IF (ExStyle & 0x8)
  {WinSetAlwaysOnTop false, "A"
   MsgBox "No longer set to stay on top: " Title, "Stay on Top Script", "4096"
  }
 ELSE
  {WinSetAlwaysOnTop true, "A"
   MsgBox "Now set to stay on top: " Title, "Stay on Top Script", "4096"
  }
}
;--------------------------------------------------------------------
; Web look-up
;--------------------------------------------------------------------
^#g:: {
 ClipSaved := ClipboardAll()
 SendInput "^c"
 sleep 500
 searchterm := A_Clipboard
 Run "http://www.google.com/search?&q=" searchterm
 A_Clipboard := ClipSaved
 ClipSaved := ""
}
^#b:: {
 ClipSaved := ClipboardAll()
 SendInput "^c"
 sleep 500
 searchterm := A_Clipboard
 Run "http://www.bing.com/search?&q=" searchterm
 A_Clipboard := ClipSaved
 ClipSaved := ""
}
^#w:: {
 ClipSaved := ClipboardAll()
 SendInput "^c"
 sleep 500
 searchterm := A_Clipboard
 Run "https://wikipedia.org/wiki/" searchterm
 A_Clipboard := ClipSaved
 ClipSaved := ""
}