toggle/cycle through capitalize-lowercase-uppercase
is it possible to make a script that will toggle/cycle through capitalize-lowercase-uppercase?
eg select some text, then clicking ctrl+y will lowercase it, clicking ctrl+y again will uppercase it, again it will capitalize it, again it will lowercase it, etc
thanks
^y:: text := clipboard RegExMatch(text, "\w", letter) StringLower, lower, letter If (letter == lower) ; case sensitive comparison StringUpper, clipboard, text Else StringLower, clipboard, text Return
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit
^y:: Clipboard = Send ^c ClipWait 1 text := Clipboard If text = Return If (mode = "U") { StringLower text, text, T ; Title case mode = T } Else If (mode = "T") { StringLower text, text mode = L } Else ; Default { StringUpper text, text mode = U } Clipboard := text ClipWait 1 Send ^v Return
the first doesnt seem to work at all
the second works, but the problem is that it releases the selection, so we have to reselect/rehighlight the text which is inconvenient
by the way, to make the script complete, it would be nice to toggle throught bold, italics, regular fonts as well but with another key shortcut
It does, you just need to have text on the clipboard already. For the sake of completion:the first doesnt seem to work at all
SendMode, Input ^y:: Critical clipx := ClipboardAll Clipboard = Send, ^c ClipWait Sleep, 50 text := Clipboard StringLen, len, text StringLower, new, text If (text == new) StringUpper, new, text Clipboard := new SendInput, {Delete}^v{Shift Down}{Left %len%}{Shift Up} Clipboard := clipx clipx = Return
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit
That's a different beast, totally depending on the target program.it would be nice to toggle throught bold, italics, regular fonts as well
any ideas?
is there a way to manipulate text (ege replace strings) without have to copy and repaste it?
how can I say if it supports that?
and if it does, whats the next step
^y:: SetTitleMatchMode 1 EM_GETSEL := 0xB0 EM_SETSEL := 0xB1 EM_REPLACESEL := 0xC2 targetCtrl = bUseClipboard := false IfWinActive ahk_class WordPadClass { targetCtrl = RICHEDIT50W1 ; Wordpad bUseClipboard := true } IfWinActive ahk_class SciTEWindow targetCtrl = Scintilla1 ; SciTE IfWinActive ahk_class Notepad2 targetCtrl = Scintilla1 ; Notepad2 IfWinActive ahk_class Notepad++ targetCtrl = Scintilla1 ; Notepad++ If targetCtrl = targetCtrl = Edit1 ; Default... Notepad and most standard edit fields ; Get position of current selection start = 0000 end = 0000 SendMessage EM_GETSEL, &start, &end, %targetCtrl%, A ; Old way (before 1.0.47.00) ;~ a := &start ;~ s := *a + (*(a + 1) << 8) + (*(a + 2) << 16) + (*(a + 3) << 24) ;~ a := &end ;~ e := *a + (*(a + 1) << 8) + (*(a + 2) << 16) + (*(a + 3) << 24) ; New way s := NumGet(start) e := NumGet(end) If (bUseClipboard) { ; One way to get the selection (more universal) ; To avoid messing the Clipboard, you might want to save ClipboardAll first, and restore it after (see manual examples) Clipboard = Send ^c ClipWait 1 text := Clipboard } Else { ; Another way, works with Edit and Scintilla, not so well with RichEdit ; Actually, it sends EM_GETSEL, WM_GETTEXTLENGTH and WM_GETTEXT (yes, get whole content of the text field!) ; before getting the selected part. Another way with RichEdit is to use EM_GETSELTEXT, but it needs to use ReadProcessMemory ; and friends to access the result... A bit of an overkill, unless wrapped in a stdlib... ControlGet text, Selected, , %targetCtrl%, A } If text = Return ; Nothing to do! If (mode = "U") { StringLower text, text, T ; Title case mode = T } Else If (mode = "T") { StringLower text, text mode = L } Else ; Default { StringUpper text, text mode = U } If (bUseClipboard) { ; One way to replace the selection (more universal) Clipboard := text ClipWait 1 Send ^v } Else { ; Another way SendMessage EM_REPLACESEL, 1, &text, %targetCtrl%, A } ; Restore selection SendMessage EM_SETSEL, s, e, %targetCtrl%, A ReturnI managed to avoid using the clipboard, but it is less universal, as it uses messages not working on all applications. So with WordPad, I fall back using the Clipboard code. The EM_REPLACESEL works with WordPad, but I preferred consistency here.
Here is a way to do it in all base Edit controls (like Notepad), RichEdit controls (like WordPad) and in Scintilla controls (used by SciTE, Notepad2 and Notepad++).
I managed to avoid using the clipboard, but it is less universal, as it uses messages not working on all applications. So with WordPad, I fall back using the Clipboard code. The EM_REPLACESEL works with WordPad, but I preferred consistency here.
^+u:: SetTitleMatchMode 1 EM_GETSEL := 0xB0 EM_SETSEL := 0xB1 EM_REPLACESEL := 0xC2 targetCtrl = bUseClipboard := false IfWinActive ahk_class WordPadClass { targetCtrl = RICHEDIT50W1 ; Wordpad bUseClipboard := true } IfWinActive ahk_class SciTEWindow targetCtrl = Scintilla1 ; SciTE IfWinActive ahk_class Notepad2 targetCtrl = Scintilla1 ; Notepad2 IfWinActive ahk_class Notepad++ targetCtrl = Scintilla1 ; Notepad++ If targetCtrl = targetCtrl = Edit1 ; Default... Notepad and most standard edit fields ; Get position of current selection start = 0000 end = 0000 SendMessage EM_GETSEL, &start, &end, %targetCtrl%, A ; Old way (before 1.0.47.00) ;~ a := &start ;~ s := *a + (*(a + 1) << 8) + (*(a + 2) << 16) + (*(a + 3) << 24) ;~ a := &end ;~ e := *a + (*(a + 1) << 8) + (*(a + 2) << 16) + (*(a + 3) << 24) ; New way s := NumGet(start) e := NumGet(end) If (bUseClipboard) { ; One way to get the selection (more universal) ; To avoid messing the Clipboard, you might want to save ClipboardAll first, and restore it after (see manual examples) Clipboard = Send ^c ClipWait 1 text := Clipboard } Else { ; Another way, works with Edit and Scintilla, not so well with RichEdit ; Actually, it sends EM_GETSEL, WM_GETTEXTLENGTH and WM_GETTEXT (yes, get whole content of the text field!) ; before getting the selected part. Another way with RichEdit is to use EM_GETSELTEXT, but it needs to use ReadProcessMemory ; and friends to access the result... A bit of an overkill, unless wrapped in a stdlib... ControlGet text, Selected, , %targetCtrl%, A } If text = Return ; Nothing to do! If (StrLen(text) != StrLen(initialText) || !InStr(text,initialText)){ initialText = %text% } If (mode = "L") { StringLower text, text mode = T } Else If (mode = "T") { StringLower text, text, T ; Title case mode = initial } Else If (mode = "initial") { text = %initialText% mode = Default } Else ; Default { StringUpper text, text mode = L } If (bUseClipboard) { ; One way to replace the selection (more universal) Clipboard := text ClipWait 1 Send ^v } Else { ; Another way SendMessage EM_REPLACESEL, 1, &text, %targetCtrl%, A } ; Restore selection SendMessage EM_SETSEL, s, e, %targetCtrl%, A Return