How to prevent blanklines on changing lowercase, uppercase, titlecase Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

How to prevent blanklines on changing lowercase, uppercase, titlecase

21 Sep 2021, 21:38

When I apply these following scripts to change lowercase, uppercase and titlecase, I get a blankline per lines at the result.

example :

from ~~~~~
as a rule, the personal information collected shall be destroyed without any delay once the purpose of its use is achieved. not withstanding the foregoing, the following information shall be preserved for the period with the cause mentioned below.

to
AS A RULE, THE PERSONAL INFORMATION COLLECTED SHALL BE DESTROYED WITHOUT ANY DELAY ONCE THE PURPOSE OF ITS USE IS ACHIEVED. NOT

WITH STANDING THE FOREGOING, THE FOLLOWING INFORMATION SHALL BE PRESERVED FOR THE PERIOD WITH THE CAUSE MENTIONED BELOW.

what I want :
AS A RULE, THE PERSONAL INFORMATION COLLECTED SHALL BE DESTROYED WITHOUT ANY DELAY ONCE THE PURPOSE OF ITS USE IS ACHIEVED. NOT
WITH STANDING THE FOREGOING, THE FOLLOWING INFORMATION SHALL BE PRESERVED FOR THE PERIOD WITH THE CAUSE MENTIONED BELOW.


How can I prevent them?

Code: Select all

Capslock & y:: ;Lowercase 
  Clipboard := ""
  SendInput, ^c ;copies selected text
  ClipWait
  StringLower Clipboard, Clipboard
  SendInput %Clipboard%
  return 

#if GetKeyState("Shift", "P")    ;Uppercase 
Capslock & y::
  Clipboard := ""
  SendInput, ^c ;copies selected text
  ClipWait
  StringUpper Clipboard, Clipboard
  SendInput %Clipboard%
  return

#if GetKeyState("Alt", "P")  ;Titlecase
  Capslock & y:: ;converts text to capitalized
  Clipboard := ""
  SendInput, ^c ;copies selected text
  ClipWait
  StringUpper Clipboard, Clipboard, T ; Title mode conversion
  SendInput %Clipboard%
Return  
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

21 Sep 2021, 21:54

Try SendInput {Text}%Clipboard% or Send ^v. I usually use the latter, because it is fast and easy, and you don't have to worry about special characters.

Demo:

Code: Select all

SendInput 1`r`n2`n`n
SendInput {Text}3`r`n4
And:

Code: Select all

Clipboard = 1`r`n2
SendInput %Clipboard%`n`n^v
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

21 Sep 2021, 22:15

mikeyww wrote:
21 Sep 2021, 21:54
I tried this following code. But it doesn't work.

Code: Select all

!k::
SendInput 1`r`n2`n`n
SendInput {Text}3`r`n4 
Clipboard = 1`r`n2
SendInput %Clipboard%`n`n^v
Return


And How can I apply the other two cases?

What's the way < SendInput 1`r`n2`n`n >.
I've never seen it ?

Thank you for your help.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase  Topic is solved

21 Sep 2021, 22:27

That's just a demo to illustrate the problem. You can try the script below.

Code: Select all

F3::case("U") ; Upper
F4::case("L") ; Lower
F5::case("T") ; Title

case(caseType) {
 Clipboard =
 Send ^c
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 Else SendInput % "{Text}" Format("{:" caseType "}", Clipboard)
}
You can change the hotkeys to whatever works for you.
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 02:00

mikeyww wrote:
21 Sep 2021, 22:27
It works. ^^ thanks a lot for your help again.

I have a question.
How can I make a sentence case.

I tried this following script. But it doesn't work for sentence case.
It works for other cases.

Code: Select all

Capslock & y::case("U") ; Upper

#if GetKeyState("Control", "P")    ;Uppercase 
  Capslock & y::case("L") 

#if GetKeyState("Alt", "P")  ;Titlecase
  Capslock & y::case("T") 


#if GetKeyState("Shift", "P")  ;Sentence case 
   Capslock & y::case("S")
Last edited by hancre on 22 Sep 2021, 02:42, edited 1 time in total.
Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 02:03

Hallo,
try:

Code: Select all

Capslock::Return
#If GetKeyState("Capslock","P")
+y::case("U") ; Upper
!y::case("T") ; Title
y::case("L") ; Lower
#If
case(caseType)
{
	Clipboard =
	Send ^c
	ClipWait, 0
	If ErrorLevel
		MsgBox, 48, Error, An error occurred while waiting for the clipboard.
	Else SendInput % "{Text}" Format("{:" caseType "}", Clipboard)
}
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 02:41

Rohwedder wrote:
22 Sep 2021, 02:03
Thank you for your help. Your code looks better than mine. ^^
Can I get sentence case by the common code?
Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 03:03

This?:

Code: Select all

Capslock::Return
#If GetKeyState("Capslock","P")
+y::case("U") ; Upper
!y::case("T") ; Title
y::case("L") ; Lower
#If
case(caseType)
{	
	Clipboard =
	Send ^{LButton} ;mark sentence in word
	Sleep, 100
	Send ^c
	ClipWait, 0
	If ErrorLevel
		MsgBox, 48, Error, An error occurred while waiting for the clipboard.
	Else SendInput % "{Text}" Format("{:" caseType "}", Clipboard)
}
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 03:17

Rohwedder wrote:
22 Sep 2021, 03:03
I added this following script to the new code.

Code: Select all

^y::case("S") ;Sentence


When I try Capslock & y with the new code, it shows an error. < An error occured while waiting for the clipboard. >

Thank you for your help.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 05:39

Code: Select all

F3::case("U") ; Upper
F4::case("L") ; Lower
F5::case("T") ; Title
F6::case("S") ; Sentence

case(caseType) {
 Clipboard =
 Send ^c
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 Else SendInput % "{Text}" (caseType = "S"
                ? Format("{:U}{:L}"       , Chr(Asc(Clipboard)), SubStr(Clipboard, 2))
                : Format("{:" caseType "}", Clipboard))
}
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 06:07

mikeyww wrote:
22 Sep 2021, 05:39
Thanks a lot for your help again. I tried your new code. It works for the three case.
But the script for sentence case doesn't work well.

It shows only uppercase for the first letters in the selected area like this :

original :
THE X/Y COORDINATES TO WHICH THE MOUSE CURSOR IS MOVED PRIOR TO CLICKING, WHICH CAN BE EXPRESSIONS. COORDINATES ARE RELATIVE TO THE ACTIVE WINDOW UNLESS COORDMODE WAS USED TO CHANGE THAT. IF OMITTED, THE CURSOR'S CURRENT POSITION IS USED.

sentence case
The x/y coordinates to which the mouse cursor is moved prior to clicking, which can be expressions. coordinates are relative to the active window unless coordmode was used to change that. if omitted, the cursor's current position is used.

But that's Ok. If necessary, I'll use the seperate script for sentence case.
I realized that sentence case would be the most useful for me. ^^

Code: Select all

#If GetKeyState("Capslock","P")
!y::case("U") ; Upper
^y::case("T") ; Title
+y::case("L") ; Lower
y::case("S") ; Sentence 

case(caseType) {
 Clipboard =
 Send ^c
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 Else SendInput % "{Text}" (caseType = "S"
                ? Format("{:U}{:L}"       , Chr(Asc(Clipboard)), SubStr(Clipboard, 2))
                : Format("{:" caseType "}", Clipboard))
}
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 06:12

The other forum posts about capitalizing sentences may help you. The problem is interesting and not straightforward, due to how punctuation is used in language.You might be able to use punctuation followed by white space as a marker of a sentence in most cases.

"This Ph.D. is a degree!" he said, "but what about a M.S. and B.S., too?" The end.
hancre
Posts: 241
Joined: 02 Jul 2021, 20:51

Re: How to prevent blanklines on changing lowercase, uppercase, titlecase

22 Sep 2021, 06:20

mikeyww wrote:
22 Sep 2021, 06:12
I'll take more care of the sentence in dialog. ^^
Thanks a lot again for your help again. ^^

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jaka1, marypoppins_1, RussF, Spawnova, usser, wilkster and 157 guests