Super UserMost useful AutoHotkey scripts?
[+42] [22] Jon Erickson
[2009-07-17 16:52:45]
[ windows automation autohotkey ]

What AutoHotkey [1] scripts have you found that proved to be extremely useful?

I'll share one that I am using for multiple monitors.

Windows + Right: Move window from the left monitor to the right monitor

WinGet, mm, MinMax, A
WinRestore, A
WinGetPos, X, Y,,,A
WinMove, A,, X+A_ScreenWidth, Y
if(mm = 1){
    WinMaximize, A

Windows + Left: Move window from the right monitor to the left monitor

WinGet, mm, MinMax, A
WinRestore, A
WinGetPos, X, Y,,,A
WinMove, A,, X-A_ScreenWidth, Y
if(mm = 1){
    WinMaximize, A
(6) AutoHotKey, or "the solution to 50% of questions on SuperUser" ! (excluding the "must-have", of course) :-] - Gnoupi
(3) Shouldn't the 1680 come from the screen resolution rather than being hard coded? - Matthew Lock
(1) @Matthew : fixed (at least I think so, I'm not fully sure about the variable, feel free to change) - Gnoupi
This is a good script, and MS implemented something fairly close in Win7. - thepaulpage
[+24] [2009-07-17 17:54:45] splattne [ACCEPTED]

Middle mouse button in combination with mouse wheel scrolling activates Alt-Tab (down) and Shift-Alt-Tab (up):

~MButton & WheelDown::AltTab
~MButton & WheelUp::ShiftAltTab

(3) plus 1 for awesomeness. - Stephen
very cool. going into my toolbox right now... - Brian
(1) I prefer left alt + scroll, but +1 anyway - RCIX
oh, very nice! I hadn't thought of this. My old mouse wouldn't be able to do it, though, which is a pity. - Phoshi
Some mice can be hard to wheel the wheel up/down while clicking. (I have a wireless entertainment 8000 which is nearly impossible to do this with.) - Chris
[+14] [2009-09-08 12:25:57] kevyn

Replace Printscreen button with Vista/Windows7 snipping tool

Run snippingtool

This does what it says on the tin, uses the Windows snipping tool instead of bog standard print screen.

Find more info on snipping tool here: snipping tool info at lifehacker [1]

update: Just a little FYI incase anyone else needs to capture multiple pages in one go...

I must admit that I now use Ducklink screen capture software now ( ducklink [2]) because it does capturing of 'scrolling windows' which I find useful. It's free, and it has a keyboard shortcut option, so I have print screen mapped to capture a region with the software instead of the snipping tool/AHK solution.


Just to clarify: Duck Capture can handle the Print Screen key on its own without AHK. Also I am trying it and it's better than Snipping Tool. :D - endolith
[+10] [2009-07-19 13:52:09] cschol

WindowPad [1]

A tool much like WinSplit Revolution, but based on Autohotkey. Works a lot better than WinSplit for me.


[+7] [2009-08-24 05:23:21] Matthew Lock

Poor man's SnagIt. Screen capture utility (puts current window screenshot into Paint for editing).

Send !{PrintScreen}
Run, mspaint.exe
WinWaitActive, untitled - Paint
    Send ^v

Clipboard enhancements

; Append to clipboard (cut)
    clipboardBefore = %clipboard%
    Send ^x
    ClipWait, 2
    clipboard = %clipboardBefore% %clipboard%

; Append to clipboard (copy)
    clipboardBefore = %clipboard%
    Send ^c
    ClipWait, 2
    clipboard = %clipboardBefore% %clipboard%

; Paste as plain text
    ClipSaved := ClipboardAll	; Save the entire clipboard to a variable of your choice.
    clipboard = %clipboard%		; Convert any copied files, HTML, or other formatted text to plain text.
    ClipWait, 2
    Send ^v
    Sleep, 1000
    Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
    ClipSaved =   ; Free the memory in case the clipboard was very large.

Boss Button [1] (hides distracting programs, restores work related ones)


SoundSet, 0 
Process, Close, pidgin.exe

WinMinimize, iTunes

SetTitleMatchMode 2
WinMinimize, Mozilla Firefox
WinMinimize, - Windows Internet Explorer

WinMaximize, - Microsoft Visual Studio
WinRestore, SourceSafe


Make active window transparent so you can look through it while the keys are held down

; Transparent
^!Space::WinSet, Transparent, 125, A
^!Space UP::WinSet, Transparent, OFF, A

Disable Caps Lock unless you press CTRL


Auto-reloads the running AutoHotkey script when you save it in an editor with CTRL-

SetTitleMatchMode 2
IfWinActive, .ahk
    Sleep, 1000
    ToolTip, Reloading...
    Sleep, 500

Awesome tips. Cheers! - Gavin Gilmour
[+7] [2009-08-29 16:29:55] user1129

Toggle the active window topmost status (always on top):

      WinSet, AlwaysOnTop, Toggle,A

+1... This one is really useful for me. Thanks. - bits
i have the same thing, but have mapped it to #t (windows+t) - Jeff Walker
[+7] [2009-09-08 12:36:59] Dimitri C.

This script does a google search on the selected text. The selection can be made in almost any application. It works by issuing a ctrl+C keypress, and then formatting the Google search URL from the clipboard. I admit it seems kind of patchy, but it works very well for me.

   tmp = %ClipboardAll% ; save clipboard
   Clipboard := "" ; clear
   Send, ^c ; simulate Ctrl+C (=selection in clipboard)
   selection = %Clipboard% ; save the content of the clipboard
   Clipboard = %tmp% ; restore old content of the clipboard
   return selection

CapsLock & g::
    selection := GetSelectedText()
    browser := GetBrowser()
    if selection <> 
        Run, %browser% ""
        Run, %browser% ""

Note: the GetBrowser() function should return the full file path of your browser application.

(1) At least in windows, just running the URL opens it in the default browser. - Phoshi
Other scripts use a ClipWait after pressing ctrl+c - endolith
[+6] [2009-07-19 12:17:25] Savvas

Any combination that disables the most annoying key in the keyboard ( caps lock [1]). Depending on your preferences it can be used to aid you in almost anything. In my case I decided to assign leftAlt+shift to it which is used to switch between languages for the keyboard (I am greek).

So :

SetCapsLockState, AlwaysOff

Capslock::Send {LAlt Down}{Shift}{LAlt Up}

personally don't need this 'cause i have enso, but would definitely use if i didnt have it. - RCIX
(4) The general hatred towards that particularly useful key in some situations, puzzles me to no end. - ldigas
(1) Most of us hit that key accidentally FAR more frequently than we do on purpose. I have it set so that capslock works (as capslock) only with a modifier. - Jaykul
@Idigas: I never use it, as I never type stuff ALL CAPS, or like the previous one, I just keep my little finger on the Shift key... Well, my script locking CapsLock/reusing it still allows to lock caps if I shift it... Still not using it. - PhiLho
[+5] [2009-07-19 18:45:50] Factor Mystic

ctrl+` to toggle a secondary display:

^`::EnableDisplayDevice("\.\DISPLAY2", -1) ; toggle secondary

Invaluable when you have a second monitor, but do gaming and want to flip it on and off without going into Windows Display Settings.

(You'll need the EnableDisplayDevice and EnumDisplayDevice scripts from a thread [1] on the AutoHotkey Community Forum.)


I've been using Ultramon's command switches, but this looks cleaner. - Phoshi
[+4] [2009-08-29 17:11:47] user1129

The Input function is very powerful and allows creation of key "chords" similar to visual studio.

This example allows you to type CTRL ~ Followed by any 2 arbitrary characters. You can then perform any action based on the 2 characters entered.


Input, TextEntry1, L1,{Esc}{Enter}{F1}{Down}{Up}

Input, TextEntry2, L1 T1,{Esc}{Enter}



if entry=cp
    ; Command prompt
    run cmd
else if entry=ca
    ; Calculator
    run calc
else if entry=ou
	; Outlook
	SetTitleMatchMode 2

	IfWinExist, Microsoft Outlook
		run outlook

	SetTitleMatchMode 1

[+4] [2010-07-19 08:40:42] pelms

Google selected text
Select text in any app (that supports 'Ctrl+c' to copy) and Win+s will Google it...

MyClip := ClipboardAll
clipboard = ; empty the clipboard
Send, ^c
Clipboard := MyClip

Is there a way to get the selected text without hijacking the clipboard? I can imagine this might conflict with things like clipboard managers. - endolith
[+3] [2010-08-13 20:51:59] yhw42

I've been using AutoCorrect.ahk for a while now. ( Here's [1] the most recent version.) It is basically a list of hotstrings for replacing common misspellings with the corrected version, based on a large list of common misspellings. For example,


I love it, as I spell poorly. You can add your own to the list using a Win-H while the misspelled word is selected.


This is the sort of thing that will constantly need to be updated. Is there an installable version that updates itself? - endolith
(1) @endolith: Do you mean update autohotkey (what runs the script) or the list of misspelled words? The script has a Win-H hotkey for quickly adding your own custom misspellings too. - yhw42
I mean update the list of misspelled words. - endolith
@endolith: Nope. I never update the list. It has over 1000 of the most common misspellings that it is 100% it knows how to correct. I can add to it if I need to, but why would I need to constantly update it? - yhw42
Any time you have a huge list of data like this, it will need updates, as mistakes are found or things need to be added, etc. The ability for users to add their own entries, and the long sections of commented-out things at the end are proof enough. Is it possible to change it to Unicode so it can handle things like ::Mohm::MΩ? - endolith
I've converted it to UTF-8 for use in AutoHotkey_L and started making modifications, see I've decided to keep the "MΩ" and other shortcuts in my regular AutoHotkey file, since they're not technically typos or misspellings. - endolith
[+3] [2009-12-13 23:13:08] Niels Teglsbo

Run a program or focus it, if it's already running.
I've been using this AutoHotkey function for a couple of years. It's like a generalized version of Phoshi's FireFox script.

; Function to run a program or activate an already running instance
RunOrActivateProgram(Program, WorkingDir="", WindowSize=""){
    SplitPath Program, ExeFile
    Process, Exist, %ExeFile%
    PID = %ErrorLevel%
    if (PID = 0) {
    	Run, %Program%, %WorkingDir%, %WindowSize%
    	WinActivate, ahk_pid %PID%

Some example key bindings using the function:

; Start programs using AltGr + some key
^!d::RunOrActivateProgram("cmd.exe", UserProfile)
^!g::RunOrActivateProgram("C:\Program Files\VMware\VMware Workstation\vmware.exe")
^!i::RunOrActivateProgram("c:\Program Files\Internet Explorer\iexplore.exe")
^!o::RunOrActivateProgram("C:\Program Files\Opera\Opera.exe")
^!p::RunOrActivateProgram("C:\Program Files\Cisco Systems\VPN Client\ipsecdialer.exe")
^!u::RunOrActivateProgram("c:\Program Files\UltraEdit\uedit32.exe")
^!w::RunOrActivateProgram("C:\Program Files\TotalCMD\TOTALCMD.EXE", "", "Max")
^!x::RunOrActivateProgram("c:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE")

I mix these shortcuts with direct calls to Run, for programs I want to have multiple instances of, e.g.:

^!r::Run "c:\windows\System32\mstsc.exe", UserProfile
^!t::Run, c:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE

[+3] [2009-08-28 11:05:00] RCIX

Poor-man's insta-calc:

ClipSave := ClipboardAll
Send ^x
Run calc.exe
WinWaitActive Calculator
Send ^v
Send {Enter}
Sleep 250
Send ^c
Send ^v
Clipboard := ClipSave

Highlight a math operation, then press Ctrl+Alt+C. It will open a calculator and paste the equation in there, copy the result, and paste it into whatever app you were in before.

(2) probably needs a bit of calculation time, but the concept is sound. I'd also add a bit of clipboard preservation code in there, so what used to be on your clipboard isn't lost. - Phoshi
Addendum: I feel as silly as you're about to for not noticing sooner, but you're literally sending the string "Enter", what you were thinking of was {Return} :P Additionally, my PC (and I doubt many!) are fast enough to for this to work without a slight sleep between return and ^c, 100ms seems to work here. Thanks for the idea, anyway :) - Phoshi
You're welcome. Currently calculations don't work right but i'll fix it up soon as possible. If you wanna help, check out… - RCIX
got it working by adding a small sleep and getting {Enter} right - Matthew Lock
Really? huh. I'll try it! Thanks! - RCIX
(1) It works! i added the clipboard preserving feature too. - RCIX
Oh, I got it working too when I said, sorry if I was vague :P It's a good script :) (22/7=3.1428571428571428571428571428571) - Phoshi
(1) That's ok. Cool huh? - RCIX
Now feed this into something like Google Calculator, Wolfram Alpha, Qalculate, GNU Units, etc so it can handle strings like "1 hundred amps * 45 V" - endolith
[+3] [2009-08-28 11:28:57] Phoshi

My most used is probably:

SetTitleMatchMode, 2
IfWinExist, Mozilla Firefox
IfWinActive, Mozilla Firefox
Send ^t
Send !d
sleep, 100
Send ^a
Run %programfiles%\Mozilla Firefox 3.1 Beta 3\firefox.exe

Opens FF if it's closed, focuses it if it's not, and opens a new tab and focuses the location bar if it is, all on capslock.

Opening that to copypaste, though, I used:


to open the script,

If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
  Send ^c
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
  Send ^v

to copypaste the script, and

    XButton1 & LButton::
CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.

GetKeyState, EWD_RButtonState, LButton, P
if EWD_RButtonState = U  ; Button has been released, so drag is complete.
   SetTimer, EWD_WatchMouse, off
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D  ; Escape has been pressed, so drag is cancelled.
   SetTimer, EWD_WatchMouse, off
   WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX  ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY

(not my script, 'songsoverruins's script) to move the window over to my other monitor quickly so I could see FF, and I'm about to

XButton1 & RButton:: 
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
send {LButton}
WinClose, A

to close the window. I also use min/max on mouse1 and scrollwheel, but I've gone on long enough. Suffice to say AHK is an integral part of my workflow, and an absolutely bloody brilliant tool.

cool but what's with the A_PriorHotkey stuff? - RCIX
Makes copypasting new doubletaps easier :P - Phoshi
i get it now. Neat! - RCIX
[+2] [2009-08-29 16:56:00] user1129

Reload the current Autohotkey script currently being edited in Notepad++. Use a single key press instead of having to right click on the tray icon and select "Reload this script".

Could be altered to work with other editors as long as the full filename can be shown in the title bar of the editor.


SetTitleMatchMode 2

IfWinActive - Notepad++
    WinGetTitle, filePath,A

    StringReplace, filePath,filePath,- Notepad++,
    StringReplace, filePath,filePath,*,

    Progress, B2 zh0 fs11 WS900 W700 H28, Reloading:   "%filePath%"

    filePath = "%filePath%"

    Run, AutoHotkey.exe /restart %filePath%

    Progress, Off


SetTitleMatchMode 1

Or just call Reload, and then you don't need to parse for the filepath. - Chris Noe
[+2] [2009-07-19 18:53:49] y0mbo

I use the Dvorak keyboard, which has the annoying flaw of moving the Cut, Copy, and Paste keys from their handy location on the standard keyboard (the Ctrl+ X, C and V keys).

So I use AutoHotKey to map them back:


(3) I'd also do vice-versa, just in case. - Phoshi
[+2] [2009-09-04 11:00:58] RCIX

SciTE4AutoHotkey [1] is not a script per se, but helps a lot with editing.


yup . It really helps a lot in editing :) - nXqd
[+1] [2010-04-30 18:58:01] tsilb
$#WheelUp::send #{NumpadAdd}
$#WheelDown::send #{NumpadSub}

So with Windows 7 Magnifier, you can use Windows Key and Mousewheel to zoom in and out. Like they should have done from the beginning.

[+1] [2010-08-26 17:51:20] Prozaker

Braces script

This script auto indents brackets (braces in the us) ({), closes it and leaves you in the middle so you can type (in Notepad++, but it can be tweaked for other editors) only if a termination character is used afterwards.

It uses EndChars, otherwise it doesn't work ( { } are an ending characters)

#Hotstring EndChars -()[]:;'"/\,.?!`n `t

My reload ctrl+alt+r


New mail

should be more refined with the %programfiles% variable

    ;switch between outlook and thunderbird 
    Run, C:\Program Files\Microsoft Office\Office12\outlook.exe /c ipm.note 
   ;Run, C:\program files\Mozilla Thunderbird\thunderbird.exe -compose,,min,

[+1] [2009-09-02 04:29:54] Matthew Lock

Quick access to commonly used programs/urls

#Numpad7::Run, firefox.exe
#Numpad8::Run, firefox.exe

[+1] [2009-09-04 09:22:50] outsideblasts
  • This one to re-assign CAPS LOCK as a window picker is great:

  • Other frequent key sentences: email address, my city (very handy with flat hunting and google map searches), "Thanks, [my name]", ...

  • And this one will hotkey F12 as a calendar viewer (W7, maybe Vista)


SetKeyDelay, -1

send, {lwin down}b{lwin up}
sleep 10
send, {left}
sleep 10
send, {enter}

Thankfully that would do nothing for me since enso traps capslock automatically... - RCIX
[+1] [2009-11-11 21:44:58] snitzr

I find that I mistype the ".com" in URLs and they end up coming out as or example.ocm

I use the following hotstrings to autocorrect these mistypes.


The asterisk in the string makes AutoHotkey perform the change instantly. The question mark ignores the fact that the .whatever is part of another word (the beginning of the URL in this case).

You might also be interested in this Firefox extension which autofixes url typos - Matthew Lock
(4) use Ctrl+Enter. - endolith