For best results, read from bottom to top, since newer posts build on former posts appearing below.

Wednesday, September 20, 2006

Watch your Typing

I really like the autocorrect feature built into so many applications today. In fact, I regret that not all programs include this commodity service. Fortunately, there's a solution.


There are, in fact, many implementations of autocorrect, but I prefer AutoHotKey. By itself, this program does nothing useful. However, it provides scriptable actions associated with keystrokes. What separates it from other programs is that it is useful beyond just assigning single key strokes. Many programs exist that enable you to map things like Alt-Ctrl-Shift-N to "launch Notepad", but AutoHotKey goes several steps beyond.

AutoHotKey watches for key sequences (or in fact, any event sequence, as I'll describe in a later post). When it sees a series of keys to which it's been directed to respond, it'll trigger a sequence, which can be a replacement text. (Or again, as I'll describe later, it can execute a useful subroutine). Of course, you can still use it to map single keystrokes to other ones, but the real power is in replacing text you type with alternative text.

Jim Biancolo cleverly converted a list of most common misspellings from Wikipedia, into a script for use with AutoHotKey. To use it, simply download and install AutoHotKey, then download this file, extract its contents (wikipedia_autocorrect.ahk) into a folder, and place a shortcut to the file in your Startup folder. When it's running, any time you type one of the handled misspellings, anywhere, it'll automatically be replaced with a correction.

There's a clever addition in this file as well: select any text then pressing Windows+H will bring up a dialog where you can add your own trigger to produce the indicated text.

The ahk script is also editable by hand in your favorite plain text editor, so you can add or remove corrections. The syntax is very straightforward: on each line, write ":R:misspelling::correction" as in ":R:anohter::another". (The leading "R" is optional in most instances - it's used to ignore special replacement characters and insert them verbatim). You'll need to tell AutoHotKey to reload the file each time you edit it. You can easily reload by selecting the "Reload This Script" option from the context menu displayed when you right-click on the AutoHotKey icon in the system tray.

Of course, all of this isn't limited to corrections. You can cleverly supply your own abbreviations, too. For example, here are a few that I've added:

::rgds::
(
Best regards,
Jeff
)
::my cell::my cell phone (555-555-1212)
::thx::thanks

Note that multi-line replacements are enclosed in parentheses. By contrast, parentheses occurring in the single-line example "my cell" will be deposited verbatim. Multi-line replacements can alternatively be expressed in a single line by using the special text "{enter}" wherever you want to insert a press of the enter key.

As I mentioned above, you can easily remap any single key, as well. In fact, this is how the Windows+H functionality was added in the wikipedia_autocorrect.ahk script. I've added a few of my own, including remapping the "forward page" and "backward page" browser keys on my IBM Thinkpad T43p to simple "PgUp" and "PgDn", with this:

Browser_Back::Send {PgUp} ; remap thinkpad button
Browser_Forward::Send {PgDn} ; remap thinkpad button

The help file installed with AutoHotKey documents these techniques and the required syntax
very well. In addition, it suggest several more complicated scripts. I'll describe one such complex script I've created in a later post.

0 Comments:

Post a Comment

<< Home