This use of the Send command makes it incredibly easy to transpose any two letters. Simply place the cursor between them and hit ALT+R (as shown in the figure.)
In Chapter Nine, “AutoHotkey Windows Clipboard Techniques for Swapping Letters: Delving into Windows Clipboard Hotkey Tricks for Switching Mistyped Letters in Any Document or Text Editor” of the book AutoHotkey Hotkey Techniques, I discuss how to select portions of text without dragging the mouse with the left button down.
This character reversing routine highlights the target letters using the SendInput command, then employs the SubStr() function to exchange the letter positions:
Code: Select all
!R::
OldClipboard := ClipboardAll
Clipboard = ;clears the Clipboard
SendInput {Left}+{Right 2}
SendInput, ^x
ClipWait 0 ;pause for Clipboard data
If ErrorLevel
{
MsgBox, No text selected!
}
SwappedLetters := SubStr(Clipboard,2) . SubStr(Clipboard,1,1)
SendInput, %SwappedLetters%
SendInput {Left}
Clipboard := OldClipboard
Return
This technique uses the SubStr() function to swap the two letters then inserts them back in place of the original letters using another SendInput command. The SendInput {Left} statement restores the cursor to the center position.
For a more detailed discussion of this technique, additional tips, and a look at the following word swapping tricks, see Chapter Nine and Chapter Ten of AutoHotkey Hotkey Techniques.