❗This script was written for AutoHotKey v1, which has been deprecated since January 2023. You can still download AHK v1, but you probably shouldn’t. I also can’t guarantee the effectiveness of this script or provide an update given I no longer use Windows. I recommend you use it as inspiration for what you might be able to do with your own script in AHK v2.


Auto Hot key is a powerful scripting language for Windows that allows you to automate almost anything by sending keystrokes and mouse clicks.

You can download Auto Hot Key at https://www.autohotkey.com.

This is a copy of my old script, which I used to automate a few things. It’s not particularly complex or well-written, but it might give you some ideas for your own script.

It is broken up into copy-able sections with some added comments, you can download the full script from the link at the bottom of the page.

Ascii art

; ____ ____ ____ ____ ___________________________ ____ ____ ____ ____ ____ ____
;||A |||u |||t |||o |||                         |||H |||o |||t |||K |||e |||y ||
;||__|||__|||__|||__|||_________________________|||__|||__|||__|||__|||__|||__||
;|/__\|/__\|/__\|/__\|/_________________________\|/__\|/__\|/__\|/__\|/__\|/__\|

Admin stuff

#NoEnv          ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn         ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%     ; Ensures a consistent starting directory.
#SingleInstance, Force          ; Only allow once 1 instance of this script.
;------------------------------------------------------------------------------------------------

; AHK Key: (Alt:!) (Win:#) (Shift:+) (Ctrl:^)

^+e::Edit           ; pulls up this script in text editor
^+r::Reload         ; reloads the script

SetCapsLockState, AlwaysOff     ; disables the capslock key functionality
  • Caps Lock is not a useful key. I use it as a modifier for triggering hotkeys.

Hotstrings

; HOTSTRINGS
;-----------
:or:ikp::XXX-XXX-XXXX              ; fills phone number
:or:ika::XXXXXX XXX XXX            ; fills address
:or:ikm::XXXX@XXXX.com             ; fills email address
:o:pll::                           ; logs in public library
    {
        Send, XXXXXXXXXXXXXXX      ; fill library card no
        Sleep, 10
        Send, {Tab}                ; switch from username to password field
        Sleep, 10
        Send, XXXX                 ; fill library pin
    }
    Return
  • ❗Only use login information you’re comfortable being stored in plain text.

Hotkeys

; HOTKEYS
;--------
CapsLock & Space::Send {Backspace}          ; trigger backspace more quickly
RCtrl & Up::Volume_Up                       ; turns the volume up
RCtrl & Down::Volume_Down                   ; turns the volume down
CapsLock & p::Winset, AlwaysOnTop, , A         ; pin/unpin window
CapsLock & v::Send, ^+v                        ; paste without formatting 
; CHARACTERS
;-----------
:or:gbp::£         ; fills £
:o:sco::🏴󠁢󠁳󠁣󠁴󠁿󠁣󠁴󠁿         ; fills saltire emoji

Function Hotkeys

Activate browser, mute tab, and switch back to previous window

; Mute Browser Hotkey
    RCtrl & m::                             ; mute active browser tab
        {
            WinGet, ActiveID, ID, A
            WinActivate, ahk_exe vivaldi.exe
            Sleep 1
            SendInput, ^m
            Sleep 1
            WinActivate, ahk_id %ActiveID%
        }
        Return
  • This comes in handy for muting internet streams with regular add breaks.
  • You will need to replace vivaldi.exe with the ahk_exe for your browser, and ^m with your browser’s hotkey for muting the active tab.

Switch back and forth between the system light/dark mode

; Toggle Darkmode Hotkey.
    RCtrl & F9::toggleDarkMode()            ; toggle dark/light mode
        toggleDarkMode()
            {
                static key := "", mode
                if !key
                    RegRead mode, % key := "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", SystemUsesLightTheme
                mode ^= 1
                RegWrite REG_DWORD, % key, AppsUseLightTheme , % mode
                RegWrite REG_DWORD, % key, SystemUsesLightTheme, % mode
            }
            Return

Google search highlighted text

; Google Hotkey
    CapsLock & g::                          ; copies and googles text
        {
            SendInput, ^c
            Sleep 10
            Run, https://www.google.com/search?q=%clipboard%
        }
        Return

Search Wikipedia for highlighted text

; Wiki Hotkey
    CapsLock & w::                          ; copy and wiki search text
        {
            SendInput, ^c
            Sleep 10
            Run, http://en.wikipedia.org/wiki/Special:Search?search=%clipboard%
        }
        Return

Temporary Hotkeys

I prefered to have all my hotkeys in one place. These hotkeys are commented out until needed. Simply remove /* and */ then reload the script to enable a hotkey, or move it to it’s own script.

Add +1 to a value stored in the clipboard

/*
    ; Incremental Clipboard Numbers.
        F1::                                        
            {
                RegExMatch(clipboard,"\d+$",match)
                match++
                clipboard:=RegExReplace(clipboard,"\d+$",match)
                send ^v
            }
            Return
    */
  • Identifies a number in the saved in the clipboard and adds +1. It then replaces the clipboard with the new value and pastes it. Useful for incrementing numbers in spreadsheets.

Spoof additional function keys

/*
    ; Function Key Faker
        F1::
            {
                tooltip, preparing to fire...
                Sleep, 3000
                Send {F13}
                sleep 10
                tooltip, BOOM!
                sleep 100
                tooltip,
            }
            Return
    */
  • This hotkey can be used when remapping keys in software, allowing you to add additional function keys. Source: Youtube.

Insert character(s) before and after highlighted text

/*
    ; Insert Characters Around Highlighted Text (Default "")
        F1::
            {
                Send, ^c
                Sleep 10
                Send, "
                Sleep 10
                Send, ^v
                Sleep 10
                Send, "
            }
            Return
    */

Insert character(s) before and after copied text

/*
    ;Insert Characters Around Copied Text (Default "")
        F1::
            {
                Send, "
                Sleep 10
                Send, ^v
                Sleep 10
                Send, "
            }
            Return
    */
  • Useful for copying quotes from books and articles.

Download the full script

You can download the full script here: AHKv1-script.ahk

AutoCorrect

I also used a community created AHK script to automatically correct commonly mistyped words. You can find that script here: AutoCorrect.ahk

You can run it as a seperate script or add it to the bottom of your main script.