Swapping Dyslexic Letters (A Favorite AutoHotkey Trick)

Sometimes the Little Things Remind Me How Much I Like AutoHotkey

As I worked on one of my blogs, I accidentally transposed two letters (probably “form” for “from” or vice versa). I placed the cursor between the errant letters and hit the R key while holding down ALT. The two characters exchanged position. Pleased with myself, I decided to highlight the letter-swapping Hotkey combination in this blog as one of my favorites.

JacksLibraryBookDeal250I’ve written quite a few AutoHotkey scripts and have implemented many of them—either as an autoload when my computer starts up or as part of my master AutoHotkey script. Having done that, I only regularly use a few of them. Those qualifying as my most-active-AutoHotkey-apps include the MousePrecise.ahk script whenever I do any graphics work, the QuickLinks.ahk script which acts as my primary Windows navigation tool, the IPFind.ahk script which helps me locate where in the world a book order originates (when someone uses the quick checkout through PayPal, I don’t get an address but IPFind tells me where they live), and the AutoCorrect.ahk script which fixes many of my errors before I even know I made them. (Oh, I often operate the handy ChangeVolume.ahk control—which uses the mouse wheel to increment speaker volume up or down when hovering over the Windows Taskbar—while I listen to Internet radio.) But, as minor as it seems, when I swap two characters in any document or Web editing field by merely placing the cursor between the two and hitting the Hotkey combination, it reminds me of how even the little things matter.

ATL+R swaps the two letters. No preselection required.

Sometimes I type “form” when I mean “from”—a common error. Most spell checkers won’t find this error. (I was surprised to find that the free form of Grammarly grammar and spelling checker did highlight a number—not all—of these errors when using from/form.) In Microsoft Word, you can write a macro which swaps any two transposed letters. My problem is that I don’t use Microsoft Word. Even if I did, the macro only works in Microsoft Word. My AutoHotkey LetterSwap.ahk Hotkey routine does the job everywhere. (Find the parallel AutoHotkey V2.0 routine on the same page.)

Without this character swapping routine, the correction would take multiple steps. I might delete one character, then reinsert it in the proper place. I could highlight one and drag it over the other character. Or maybe, highlight both and retype the letters in the correct order. In many cases, Grammarly finds the problem, but, even then, I find it easier to just place the cursor between the two letters and hit the swapping Hotkey combination.

While a little more complicated than writing Hotstring replacements, the letter-swapping routine uses the Standard AutoHotkey Clipboard Routine and traditional commands to make it happen:

  OldClipboard := ClipboardAll
  Clipboard := ""             ; Clears the Clipboard
  SendInput {Left}+{Right 2}  ; Selects the two letters
  SendInput, ^c
  ClipWait 0                  ; Pause for Clipboard data
  If ErrorLevel
    MsgBox, No text selected!
  SwappedLetters := SubStr(Clipboard,2) . SubStr(Clipboard,1,1)
  SendInput, %SwappedLetters%
  SendInput {Left}            ; Centers the cursor
  Clipboard := OldClipboard

You can find a discussion of this routine (plus other word-swapping routines) in “Chapter Nine: AutoHotkey Windows Clipboard Techniques for Swapping Letters” in the section  “Eliminating the Requirement for Pre-Selected Text” of the book AutoHotkey Hotkeys: Tips, Tricks, Techniques, and Best Practices.


This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free. I’ve never used the paid version of the software so I can’t give an opinion on that service.)

2 thoughts on “Swapping Dyslexic Letters (A Favorite AutoHotkey Trick)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s