Jump to content

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

Convert text - uppercase, lowercase, capitalized or inverted


  • Please log in to reply
33 replies to this topic
Terka
  • Members
  • 53 posts
  • Last active:
  • Joined: 21 Aug 2007
would it be possible to toggle between all of them?
upper/lower/capitalised
so instead of 3 combination you will have one-if pressed
once, upper
twice lower
3x, capitalised
and so on
quit from the loop after un-pressed the alt or control thing.

sashabe
  • Members
  • 24 posts
  • Last active: Aug 05 2013 11:34 AM
  • Joined: 09 Oct 2006

would it be possible to toggle between all of them?
upper/lower/capitalised
so instead of 3 combination you will have one-if pressed
once, upper
twice lower
3x, capitalised
and so on
quit from the loop after un-pressed the alt or control thing.

Yeah, like in MS Word.

CoastToast
  • Guests
  • Last active:
  • Joined: --
THIS IS LINE 1.



THIS IS LINE 3. THERE IS ONE BLANK LINE ABOVE AND BELOW THIS LINE.



THIS IS LINE 5.
Copy the entire text in the box above and paste it into Notepad. Then press Ctrl+A to select all. Then try using any of the sentence-case scripts that have been posted in this thread. You will see that the script does not work properly.

kchamb3
  • Members
  • 11 posts
  • Last active: Apr 10 2014 01:04 PM
  • Joined: 25 Jan 2013

CoastToast is right, anyone have a clue as to why it doubles the empty lines with each iteration? 



robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 29 2017 12:42 PM
  • Joined: 11 Nov 2012

@CoastToast and @kchamb3 - I had asked this same question about the double empty lines. Some nice people on this forum provided the explanation and answer here: http://www.autohotke...-for-multiline/

 

Here's a working example for Ctrl+Alt+U to covert selected text to Uppercase:

SendMode Input  ; Forces Send and SendRaw to use SendInput buffering for speed.

;Replace selected text with uppercase
^!u::
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, OutputText, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, OutputText, OutputText
	SendRaw % OutputText
        VarSetCapacity(OutputText, 0) ;free memory
Return


kchamb3
  • Members
  • 11 posts
  • Last active: Apr 10 2014 01:04 PM
  • Joined: 25 Jan 2013

Wow thanks for such a snappy reply! I will give this a try tonight!



kchamb3
  • Members
  • 11 posts
  • Last active: Apr 10 2014 01:04 PM
  • Joined: 25 Jan 2013

Great, soi messed around with this a little get it to work inside excel and some other applications that weren't liking the SendRaw for some reason. Here is a working example that toggles through Upper/Lower/Sentence while utilizing that line-break discovery of yours robert. Thanks!

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

cycleNumber := 1

^+d::
If (cycleNumber==1)
{
ConvertUpper()
cycleNumber:= 2
}
Else If (cycleNumber==2)
{
ConvertLower()
cycleNumber:= 3
}
Else
{
ConvertSentence()
cycleNumber:= 1
}
Return





ConvertUpper()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}

ConvertLower()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}

ConvertSentence()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard ;Convert case
	Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
	Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}


yosang
  • Members
  • 57 posts
  • Last active: Apr 11 2013 01:18 PM
  • Joined: 28 Nov 2012

WOW 

kchamb3 

 

That was just awesome man, greatest tool ever.



yosang
  • Members
  • 57 posts
  • Last active: Apr 11 2013 01:18 PM
  • Joined: 28 Nov 2012

Is there a way to add a function that remove spaces from a sentece in this case? 

 

using this type of script, I've tried with ReGex before but had a bad experience with it.

 

#+r::
Clipboard := ""
Send, ^x ; cut
Send, % RegExReplace(clipboard, "\s", "") ; send clipboard content with your characters around it
clipboard := saved ; restore clipboard
saved := "" ; clear saved
Return

 

 

Edit:

 

Found out happy.png

 

If anyone has use for it, here is the edited code from above.

 

SendMode Input

cycleNumber := 1
 
#Capslock::
If (cycleNumber==1)
{
ConvertUpper()
cycleNumber:= 2
}
Else If (cycleNumber==2)
{
ConvertLower()
cycleNumber:= 3
}
Else
{
ConvertSpaces()
cyclenumber:=1
}
Return

ConvertUpper()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}
 
ConvertLower()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}
 
ConvertSpaces()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
        StringReplace, ClipBoard, Clipboard, %A_SPACE%, ,
	Len:= Strlen(Clipboard) ;Set number of characters
    Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}


kchamb3
  • Members
  • 11 posts
  • Last active: Apr 10 2014 01:04 PM
  • Joined: 25 Jan 2013

Nice clean up job! While I don't doubt that this function is important I am curious as to what the application for removing spaces from sentences is.. could you give an example?



kchamb3
  • Members
  • 11 posts
  • Last active: Apr 10 2014 01:04 PM
  • Joined: 25 Jan 2013

As for that code I posted earilier, changing the modified input to a paste rather than individual character sends obviously made it a lot faster..

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


cycleNumber := 1

#IfWinNotActive ahk_class XLMAIN

^+d::
If (cycleNumber==1)
{
ConvertUpper()
cycleNumber:= 2
}
Else If (cycleNumber==2)
{
ConvertLower()
cycleNumber:= 3
}
Else
{
ConvertSentence()
cycleNumber:= 1
}
Return





ConvertUpper()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard
	Len:= Strlen(Clipboard)
    SendInput, ^v ;pastes new text
	Send +{left %Len%}
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave
}

ConvertLower()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard
	Len:= Strlen(Clipboard)
    SendInput, ^v ;pastes new text
	Send +{left %Len%}
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave
}

ConvertSentence()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard
	Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
	Len:= Strlen(Clipboard)
    SendInput, ^v ;pastes new text
	Send +{left %Len%}
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave
}

#IfWinNotActive

;RELOAD
!+^x::
   SplashTextOn,,,Updated script,
   Sleep,200
   SplashTextOff
   Reload
   Send, ^s
return


robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 29 2017 12:42 PM
  • Joined: 11 Nov 2012

@kchamb3 - since you are not using the variable OutputText and doing everything within the Clipboard variable itself - there is no need for the line:

VarSetCapacity(OutputText, 0) ;free memory

 

You can remove it.

 

I only used the "OutputText" variable instead of doing modifications to the Clipboard variable because I have a separate Clipboard History script running that uses "OnClipboardChange" to detect and record all modifications made to the Clipboard - and so I did not want to modify the Clipboard.

 

For you, you are actually rather using "clipSave" as a Temp variable. So I would use this at the end of your script to free the memory used by this variable:

VarSetCapacity(clipSave, 0) ;free memory



yosang
  • Members
  • 57 posts
  • Last active: Apr 11 2013 01:18 PM
  • Joined: 28 Nov 2012

Guys...

 

Im trying to use this function on a Citrix Client window, I have been searching for help without luck.

 

Does anyone know a workour for this? it seends that the client is having trouble with the simulated keys, it just glitches and doesnt work right,.



sebas39
  • Members
  • 1 posts
  • Last active: Jul 30 2014 11:44 PM
  • Joined: 30 Jul 2014

Great ahk. Thanks JDN

 

i changed it a little bit, so that it works directly on the selected text, using ^x first

(as it does about the same in win word with +F3)

 

Therfore, i also used hotkeys with F3 combinations (as i use the ^l or ^u hotkeys already for other purposes.

 

And i also added the "Sentence case" one of ManaUser.

 

 

 

 

----------------------------------------------------------------------------------

 

#+F3::                ; Convert TEXT to UPPER
 Send, ^x
 sleep, 150
 StringUpper Clipboard, Clipboard
 Send %Clipboard%
RETURN

#^F3::                ; Convert text to lower
 Send, ^x
 sleep, 150
 StringLower Clipboard, Clipboard
 Send %Clipboard%
RETURN

#+^F3::                ; Convert Text To Capitalized
 Send, ^x
 sleep, 150
 StringUpper Clipboard, Clipboard, T
 Send %Clipboard%
RETURN

#!F3::                ; cONVERT tEXT tO iNVERTED
 Send, ^x
 sleep, 150
 Lab_Invert_Char_Out:= ""
 Loop % Strlen(Clipboard) {
 Lab_Invert_Char:= Substr(Clipboard, A_Index, 1)
 if Lab_Invert_Char is upper
 Lab_Invert_Char_Out:= Lab_Invert_Char_Out Chr(Asc(Lab_Invert_Char) + 32)
 else if Lab_Invert_Char is lower
 Lab_Invert_Char_Out:= Lab_Invert_Char_Out Chr(Asc(Lab_Invert_Char) - 32)
 else
 Lab_Invert_Char_Out:= Lab_Invert_Char_Out Lab_Invert_Char
 }
 Send %Lab_Invert_Char_Out%
RETURN

#+!F3::            ; Sentence case

          ; but the ! disapears; have not foud solution for that

  Send, ^x
  sleep, 150
  StringLower, Clipboard, Clipboard
  Clipboard := RegExReplace(Clipboard, "((?:^|[.!?]\s+)[a-z])", "$u1")
  Send %Clipboard%
RETURN



shnk
  • Members
  • 3 posts
  • Last active: Aug 17 2014 06:45 AM
  • Joined: 24 Mar 2014

For sake of completeness, it would be very helpful if someone can write script for converting text for Title Case. By title case, I mean every word of the sentence are capital except few prepositions, e.g. of, and, or etc.