Auto capitalize the first letter of a sentence after a period. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HonestWord
Posts: 6
Joined: 24 Mar 2023, 00:09

Auto capitalize the first letter of a sentence after a period.

Post by HonestWord » 24 Mar 2023, 00:52

hi, I'm a beginner in AutoHotkey scripts

so i was looking for a way to capitalize first letter of a sentence after a period. and found out this Topic, and this script on it

Code: Select all

#NoEnv
#SingleInstance Force

str = he left me. she is: they are, he.
MsgBox, % new := RegExReplace(str, "^\w|(?:\.|:)\s+\K\w", "$U0")

; Output:

; He left me. She is: They are, he.
This script make the text after capitalized shows in a message box, but not custom text, so i toyed with it a little bit to make it use custom text and i did end up with this:

Code: Select all

#NoEnv
#SingleInstance Force

; Get the text from the clipboard
Clipboard := ""
Loop, 5 {
  ClipWait, 1
  If !ErrorLevel
    Break
}

; Apply the RegExReplace function to the clipboard text
new := RegExReplace(Clipboard, "^\w|(?:\.|:)\s+\K\w", "$U0")

; Show the modified text in a message box
MsgBox, % new
But the problem with this code it only show text in message box, and for me i want it to show the capitalized text in the same place i'm writing, anywhere.

so i toyed more with the code and result is this:

Code: Select all

#NoEnv
#SingleInstance Force

; Get the text from the clipboard
Clipboard := ""
Loop, 5 {
  ClipWait, 1
  If !ErrorLevel
    Break
}

; Apply the RegExReplace function to the clipboard text
new := RegExReplace(Clipboard, "^\w|(?:\.|:)\s+\K\w", "$U0")

; Send the modified text to the active window
Sleep 1000 ; Wait for 1 second to switch to the chat window
SendInput, % new
but the problem with this code is that it need me to copy text for it to replace. so what i want is that:
script to make it change first letter in sentence after i hit period to capital.

Example:
hello how are you.

result after i clicked (.) :
Hello how are you.

Thanks for reading !

Summary:
So, I need help in creating a script that will automatically capitalize the first letter in a sentence after I hit the period without having to copy and paste the text and in real time. i don't mind if it's on v1 or v2. Thanks for reading ! :D

Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Auto capitalize the first letter of a sentence after a period.  Topic is solved

Post by Rohwedder » 24 Mar 2023, 04:04

Hallo,
try:

Code: Select all

Loop
{
	ih := InputHook("V", "{.}"), ih.Start(), ih.Wait()
	Pos := 1 - RegExMatch(ih.Input, "(*UCP)[[:alpha:]]", Chr) + StrLen(ih.Input)
	StringUpper, Cap, Chr
	SendInput,% (Cap == Chr)?"":"{Left " Pos "}{Bs}" Cap "{Right " Pos "}"
}

HonestWord
Posts: 6
Joined: 24 Mar 2023, 00:09

Re: Auto capitalize the first letter of a sentence after a period.

Post by HonestWord » 24 Mar 2023, 07:06

Rohwedder wrote:
24 Mar 2023, 04:04
Hallo,
try:

Code: Select all

Loop
{
	ih := InputHook("V", "{.}"), ih.Start(), ih.Wait()
	Pos := 1 - RegExMatch(ih.Input, "(*UCP)[[:alpha:]]", Chr) + StrLenHih.Input)
	StringUpper, Cap, Chr
	SendInput,% (Cap == Chr)?"":"{Left " Pos "}{Bs}" Cap "{Right " Pos "}"
}
Thanks for the script you shared with me earlier. Seriously, you're a genius! It has saved me so much time and hassle from having to manually capitalize every sentence.

The script works perfectly. <3

User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Auto capitalize the first letter of a sentence after a period.

Post by mikeyww » 24 Mar 2023, 07:36

Sure it works? i don't know.

HonestWord
Posts: 6
Joined: 24 Mar 2023, 00:09

Re: Auto capitalize the first letter of a sentence after a period.

Post by HonestWord » 24 Mar 2023, 07:59

mikeyww wrote:
24 Mar 2023, 07:36
Sure it works? i don't know.

Yes it works. This is a test for it. And i also modified the script to make it works with question mark? Not just period.

HonestWord
Posts: 6
Joined: 24 Mar 2023, 00:09

Re: Auto capitalize the first letter of a sentence after a period.

Post by HonestWord » 24 Mar 2023, 08:03

mikeyww wrote:
24 Mar 2023, 07:36
Sure it works? i don't know.
Here's a video for the test :D


User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Auto capitalize the first letter of a sentence after a period.

Post by mikeyww » 24 Mar 2023, 19:57

No offense, but I find your test video to be pretty lame! It doesn't test a lot, and a video is not really needed for testing of this specific script. We can just examine a set of specific strings.

My interpretation of your previous post is that the initial script did not work, you revised it to fix it for ?, you did not post any such revision, and you are satisfied with the results. Good outcome! At least it is working the way that you need, and that is what matters. To be fair, your original script did seem to meet your subject, "Auto capitalize the first letter of a sentence after a period." I was just thinking that a lot of sentences do not end in a period. Furthermore, of course, sentences end in other characters, and these characters do not exclusively mark the ends of sentences. Thus, demarcation of sentences is trickier than meets the eye.

Post Reply

Return to “Ask for Help (v1)”