Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

toggle/cycle through capitalize-lowercase-uppercase


  • Please log in to reply
15 replies to this topic
user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
hello

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

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Untested e.g.

^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


Helpy
  • Guests
  • Last active:
  • Joined: --
^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



user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
thanks

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

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

the first doesnt seem to work at all

It does, you just need to have text on the clipboard already. For the sake of completion:

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


Helpy
  • Guests
  • Last active:
  • Joined: --

it would be nice to toggle throught bold, italics, regular fonts as well

That's a different beast, totally depending on the target program.

user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
I really need this, but I didnt find any solution satisfying (not the bold, etc, just the capitals etc)

any ideas?

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Check out this thread for a simple but workable method to re-select the pasted text.

user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
thanks

is there a way to manipulate text (ege replace strings) without have to copy and repaste it?

Helpy
  • Guests
  • Last active:
  • Joined: --
Again, it depends on your text editor: if it answers EM_ messages, it can be done. If it has another known API, it can still be done.

user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
my text editors are notepad, notepad2, emeditor, ms word, openoffice

how can I say if it supports that?

and if it does, whats the next step

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
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++).
^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
Return
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.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Cephus
  • Guests
  • Last active:
  • Joined: --
Man, if this worked in Microsoft SQL Server Management Studio, it would be golden for me.

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.



engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
just turn it into a hotkey to go via your clipboard.

rfDennis
  • Guests
  • Last active:
  • Joined: --
^+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