Have you ever written the same repetitive phrases in emails to customers or instructions during code development? Do you have an amount of boring tasks that could become a little faster and automated? If so, give AutoHotkey a try!
AutoHotkey is a free and easy to use tool for Windows that allows you to create custom shortcut and automate tedious tasks with a simple script.
Usage examples
This a set of very simple tasks, AutoHotKey can do a lot more!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. #SingleInstance force SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. ; This is a comment ; Help Syntax Shortcut: ^!Numpad9 = Ctrl + Alt + 9 num pad (or AltGr + 9 num pad) ; ^j = Ctrl + j ; Send command simulate pression of keyboard keys ; Attention!! ; `r or `n (new line) or {space} may work as confirm for a Windows popup ; If you want to send a text with more rows, use sendUsingClipboard method ; Special Char {space}{tab} ; ########## VARIOUS ########## ; Ctrl + Alt + Numpad1 Write your telephone number ^!Numpad1:: Send 333 1234567 Return ; Write Current Timestamp ^!Numpad2:: FormatTime, currentDateStr,, yyyy-MM-dd-HHmmss Send %currentDateStr% Return ; Use an object prefix in your emails: ; Ctrl + Alt + 1 writes '[BENZ W124 Issues] ' ^!1:: Send [BENZ W124 Issues]{space} Return ; Launch Windows calculator ^!NumpadAdd:: Run calc.exe Return ; ########## SQL ########## ; Ctrl + Alt + 9 writes SELECT * FROM ; moving the cursor before the ; ^!Numpad9:: Send SELECT * FROM{space};{Left} Return ; Copy a table name, then run this macro, it will compose: ; SELECT * FROM [paste_text] WHERE ^!Numpad8:: string = SELECT * `nFROM %Clipboard% `nWHERE `; SendUsingClipboard(string) Send {Left} Return ; Paste the Oracle TO_DATE function ; "TO_DATE('2020-03-26 00:00:00','yyyy-mm-dd hh24:mi:ss')" ^!Numpad7:: FormatTime, currentDate,, yyyy-MM-dd tempStr := "TO_DATE('" currentDate " 00:00:00','yyyy-mm-dd hh24:mi:ss')" SendUsingClipboard(tempStr) Return ; Send a long query with more rows ^!7:: string := " ( SELECT a, b, c FROM TAB_A JOIN TAB_B ON (TAB_A.ID = TAB_B.ID) WHERE TAB_A.NAME like '%testName%'; )" SendUsingClipboard(string) Return ; ########## COMPLEX ########## ; Open URL in Browser ; Default browser: Run http://issues.it:8080/browse/%clipboard% ; Browser in new window: ; Run chrome.exe "https://mail.google.com/" " --new-window " ; Run, firefox.exe -new-window https://mail.google.com/ ; Copy selected test, compose URL, open in Chrome new tab ^!j:: clipboardSaved := ClipboardAll Clipboard := "" Send, ^c ClipWait, 1, 1 ; Wait for the clipboard to contain the copied text. Run http://mysite.it:8080/browse/%clipboard% ; default browser Clipboard := clipboardSaved ; keep previous cliboard content return ; Another way, activating Chome and sending keys ^!k:: clipboardSaved := ClipboardAll Clipboard := "" Send, ^c ClipWait, 1, 1 ; Wait for the clipboard to contain the copied text. IfWinNotActive, ahk_exe chrome.exe WinActivate, ahk_exe chrome.exe Send, ^t ; Ctrl + T -> New Tab Send, http://mysite.it:8080/browse/%clipboard% Clipboard := clipboardSaved ; keep previous cliboard content return ; Run cmd and type the ping command to ping an URL ^!p:: Run, cmd.exe WinWait, ahk_class ConsoleWindowClass WinWaitActive, ahk_class ConsoleWindowClass Send ping{space} Return ; Launch windows bat script with PAR1 parameter ^!6:: Run, C:\utils\deployEar.bat PAR1 Return ; ########## METHODS ########## SendUsingClipboard(string){ ; Save previous clipboard prevClipboard := ClipboardAll Clipboard := "" ; Empty the clipboard first Clipboard := string ClipWait, 1, 1 ; Wait for the clipboard to contain text SendInput, ^v ; Paste ; Wait paste happend before resotring clipboard Sleep, 250 ; 500ms is hopefully more than enough ; Restore clipboard content Clipboard := prevClipboard return } |
How to install
- Download AutoHotkey, there’s also the portable version if you aren’t system administrator (Download AutoHotkey .zip)
- Create a new text file with .ahk extension, e.g. myScript.ahk and write your commands
- Set the .ahk extension to be opened by default with AutoHotKey: right click myScript.ahk – Properties – Open with: AutoHotkey
- Set AutoHotkey to be always active:
- create a shortcut to myScript.ahk (right click – > Send to desktop, create shortcut)
- copy the shortcut in the Windows startup folder (Usually C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup OR C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)
- Double click myScript.ahk to run AutoHotKey
Documentation
- Intro autohotkey.com/docs/Hotkeys.htm#Intro
- KeyList autohotkey.com/docs/KeyList.htm
- Instruction Send autohotkey.com/docs/commands/Send.htm
This post is priceless. Where can I find out more?