ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Free Windows Text Editor that transposes last 2 characters typed on Control-t ??

<< < (3/3)

MilesAhead:
Looking around on ahk forum I saw that I was overly concerned about the clipboard when doing a hotkey for transposing characters. Using the clipboard has the advantage that I can move the caret, then later come back and fix a transpose typo.  This implementation is just a minimal macro.  It will not work correctly unless there are at least 2 characters to the left of the caret when you hit the hotkey. If the caret is at the start of a line or to the right of the first character, the macro will just end up eating a character. Also the app taking the input must be in Insert Mode.  Still, I get quite a bit of use out of it.  Anytime I want to add an app I just check that the app doesn't use ^t itself, then add its class name to the list for the window group.


--- ---#SingleInstance force
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
GroupAdd,EditorGroup, ahk_class TFormEditPadLite  ;EditPadLite
GroupAdd,EditorGroup, ahk_class wxWindowClassNR   ;FBIde
GroupAdd,EditorGroup, ahk_class SciTEWindow       ;Scite
GroupAdd,EditorGroup, ahk_class MAINFBEDIT        ;FBEdit
GroupAdd,EditorGroup, ahk_class Notepad           ;Notepad
GroupAdd,EditorGroup, ahk_class TFormMain         ;TreePad
GroupAdd,EditorGroup, ahk_class Chrome_WidgetWin_0   ;Chrome Browser
GroupAdd,EditorGroup, ahk_class MozillaUIWindowClass ;Firefox Browser

#IfWinActive, ahk_Group EditorGroup
^t::
  ClipSaved := ClipboardAll ; save entire clipboard
  Clipboard= ; clear clipboard
  Send {Shift Down}{Left}{Shift Up} ; select char left of caret
  Send ^c ; copy char
  ClipWait,0 ;give copy time to complete
  ; the caret is positioned to insert
  ; the char from the clipboard. Editor
  ; must be in Insert Mode for it to work.
  ; The char is inserted, and caret positon restored.
  ;
  Send {Right}
  Send {BackSpace}
  Send {Left}
  Send {Raw}%Clipboard% ; avoid puntuaction being interpreted
  Send {Right}
  Clipboard := ClipSaved
  ClipSaved = ; free memory
Return

Navigation

[0] Message Index

[*] Previous page

Go to full version