Tool of the Week: Autocorrect Macros with AutoHotkey

Although I'd much rather be coding all day, a good part of my job involves writing e-mail and creating documentation.  And since both can tend to be boring and repetitive, I saw those activities as new avenues for coding.

I found a great (free!) tool called AutoHotKey, a macro language for Windows that allows you to add code for anything and everything you see on the screen.  It's really quite deep, providing for certain actions based on what window is currently selected.  Back in Windows XP and Vista days, I had a macro written that closed the desired application in the taskbar with a middle click of the mouse.  I haven't revisited the script since Windows 7 hit the scene, but I'll bet there's a way to do it.

CloseWindowOnMiddleClick.ahk:

#SingleInstance force

MButton::
MouseGetPos, , , id, control
WinGetClass class, ahk_id %id%

if (control = "ToolbarWindow322" || control = "ToolbarWindow324") {
    Send {RButton}{Esc}{Esc}
    WinGetActiveTitle currentWindow

    if (currentWindow != "") {
        WinClose %currentWindow%
    }

    else {
        Send {MButton}
    }
}

else {
    Send {MButton}
}

return
What I do use AutoHotkey for on a daily basis is a global auto-correct.  Rather than leveraging Microsoft Word's autocorrect feature, I'll add to my existing script whenever I have a new abbreviation that I want spelled out or a new typo that I'll inevitably make so it can be applied across any application.  It's also useful for repetitive stuff: if I type "ssf", it'll replace it with:
SELECT *
FROM 

WHERE
... and it will automatically move the cursor above the "WHERE" clause so I can immediately type the table name in the SQL query.  Here's a sample of my autocorrect macro:
Autocorrect.ahk:
::framwork::framework
::fyi::FYI
::gui::GUI
::ktnx::ok, thanks
::ktny::ok, thank you
::lan::LAN
::sql::SQL
::mgmt::management
::mtg::meeting
::np::no problem
::pls::please
::powerpoint::PowerPoint
::prodn::production
::req::requirement
::reqs::requirements
::sharepoint::SharePoint
::ssf::SELECT *{enter}FROM {enter}WHERE {up}
::ssn::SSN
::ssns::SSNs
::stirng::string
::ty::Thank you
::vpn::VPN
::cache'::Caché
I know I've barely scratched the surface of AutoHotKey.  It's a full-blown programming language and I've just documented it like it's just a simple toy.  But even though I don't have a full grasp of its power, I'm still able to get it to perform simple feats that make redundant parts of my life just a little bit more automated and a little less repetitive.

Leave a Reply

Your email address will not be published. Required fields are marked *