Practical AutoHotkey: AutoHotkey reference

This is an edited excerpt from my book Practical AutoHotkey: How to get faster at work with text expansion and automation which is available on Kindle. If you find this useful I’d apperciate if you bought a copy, left a review or simply signed up for my mailing list.

Chapter 10: AutoHotkey Reference

Key reference

For details of additional key options and the most current information, always refer to the AutoHotkey website on Hotkeys: https://autohotkey.com/docs/Hotkeys.htm

Windows key:

# or{LWin}or{RWin}` Alt key:

! or {Alt} or {LAlt} or {RAlt}

Control key:

^ ; Control key in AutoHotkey is upcaret

Shift key:

+ ; Shift key in AutoHotkey is a plus sign`

SEND reference

Note: You almost always want to use the SendInput command rather than the Send command. It is a little slower, but is much more intelligent and typically does what you want rather than what you say.

Whitespace keys:

{Space} {Tab}

Enter key:

{Enter}

Arrow keys:

{Up} {Down} {Left} {Right}

Text editing keys:

{Backspace} {Delete} {Insert}

Punctuation keys (sends what is inside the curly braces):

{!} {#} {+} {^} {{} {}}

Ending Character

Under normal text expansion, you must type one of a specific set of keys to trigger the expansion. These are ones that would normally indicate the end of a sentence or word in English, and they are enabled by default:

space enter tab
: ; " '
, . ? ! 
- { } [ ]

These can be remapped to whatever you want:

#Hotstring EndChars <list all of your new EndChars here; will take effect globally>

Details on the AutoHotkey website: End Character.

Symbol reference

A list of Microsoft Windows alt codes is available at http://www.alt-codes.net/.

By no means exhaustive, but here are some common symbols you may want to quickly insert:

Copyright

Type copyrr for immediate expansion to the copyright symbol, no space needed to trigger (because usually it’s “copyright symbol”“year” without a space between).

:*:copyrr::{ASC 0169}

Euro

Type eurr for immediate expansion to the Euro symbol, no space needed to trigger (because usually it’s usually the euro symbol immediately followed by a monetary amount, without a space between).

:*:eurr::{ASC 0128}

em dash

Triple hyphen sends em dash, consider also using a double hyphen to trigger this hotstring, if you often write em dashes. (A single hyphen would also work until you try to write a date like 2016-03-29).

:*:---::{ASC 0151} ; triple hyphen sends em dash

I also like:

:*:---::&mdash; ; triple hyphen creates em dash in HTML.

Built In Variables

Please see: https://autohotkey.com/docs/Variables.htm#BuiltIn. This includes time and date variables, and a variety of variables that will come in handy if you’re doing serious amounts of AutoHotkey scripting, but are more than most people need for basic text expansion.

Sending a key several times

To SEND a key multiple times with the SEND command, include a number after the key:

{Left 6} ; where 6 is the number of times you want to send that key

Text expansion

Expanding ‘hello’ to ‘Hello, how are you?’:

::hello::Hello, how are you?

Expanding ‘now’ to ‘I want this to expand right away.’ as soon as you finish typing ‘now’, instead of waiting for the user to type an Ending Character.

:*:now::I want this to expand right away.

Expanding ‘llo’ to ‘Limited Liability Occupation’, even if it’s part of another word, like ‘hello’. The catch here is that you still have to type an Ending Character to trigger the hotstring:

:?:llo::Limited Liability Occupation

If you want that text to always expand, even in the middle of a word like ‘example’, and without an Ending Character, then use the star and question mark together:

:?*:amp::Ampere (commonly abbreviated as amp) is a unit of electric current.

Launching programs

Launching programs with AutoHotkey is simple (pick whatever key you want):

F3::run Outlook.exe  ; launch Microsoft Outlook, F3
#W::run winword.exe  ; launch Microsoft Word, Windows key-W
^E::run excel.exe    ; launch Microsoft Excel, Control key-E
!P::run powerpnt.exe ; launch Microsoft PowerPoint, Alt key-P

Opening web pages

F4::run http://www.google.com ; open Google.com in the default web browser.

Window management

For best results, tell AutoHotkey to look for the text of the title you are specifying anywhere in the window title:

SetTitleMatchMode, 2

For more information — including the option to use Regular Expressions in your window titles — refer to AutoHotkey.com: https://autohotkey.com/docs/commands/SetTitleMatchMode.htm.

Hide a window

Note: Don’t use this code unless you’re prepared to issue a WinShow, otherwise your window will be lost to you.

WinHide, <title of window>

Minimize a window

WinMinimize, <title of window>

Show a window

WinShow, <title of window>

Show/hide a window

Please see the final code in Chapter 8: Hiding and Unhiding Windows for Fun, Profit, and Continued Employment.

Show/hide a window, or open it if it isn’t already running

Please see the show/hide/run section of Chapter 8: Hiding and Unhiding Windows for Fun, Profit, and Continued Employment.

Chapter 11: Recipes for Specific Tasks, Specific Programs

Bonus content: launch Microsoft Word:

run winword.exe "C:\Users\username\file\location.docx"

Launch Outlook ‘New E-mail’ window.

F3::run Outlook.exe /c ipm.note

Launch Outlook Calendar window.

F2::run Outlook.exe /select outlook:calendar

Launch your web browser of choice with a new tab

Chrome

F6::run chrome.exe www.example.com

Edge

It’s possible to launch Edge from AutoHotkey, but it’s not pretty nor recommended, unless it’s your default browser, then see ‘Opening Web Pages’ in the previous section.

Firefox

F6::run firefox.exe -new-tab

Launch your web browser with a specific page in a new window

Chrome

F6::run chrome.exe /new-window www.example.com

Edge

It’s possible to launch Edge from AutoHotkey, but it’s not pretty nor recommended.

Firefox

F6::run firefox.exe -new-window example.com

Show/hide your music player

Spotify

; To show/hide Spotify window
F4::
  {
    ifWinNotActive, ahk_Class SpotifyMainWindow
    {
      WinShow, ahk_Class SpotifyMainWindow
      WinActivate, ahk_Class SpotifyMainWindow
    }
    else
    {
      WinClose ahk_Class SpotifyMainWindow   ;; assumes the 'minimize on close' option set in Spotify settings is checked.
    }
  }
  return

Amazon Music

; To show/hide Amazon Music window
F4::
  {
    ifWinNotActive, Amazon Music
    {
      WinShow, Amazon Music
      WinActivate, Amazon Music
    }
    else
    {
      WinMinimize Amazon Music ; so that it loses 'focus' and pressing the key combo will bring it back again right away, even if we were just looking at it
      WinHide Amazon Music
    }
  }
  return

This is an edited excerpt from my book Practical AutoHotkey: How to get faster at work with text expansion and automation which is available on Kindle. If you find this useful I’d apperciate if you bought a copy, left a review or simply signed up for my mailing list.

You may also like: