Capitalize first paragraph letter (not just after .?!)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 14:33

There is a good number of AHK scripts to capitalize a first sentence letter following punctuation marks such as .?!

What about a new paragraph? Is there a way to capitalize the first letter of a new paragraph first sentence?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 17:08

Perhaps something like this:

Code: Select all

q:: ;capitalise first letter of 'paragraph'
vText := "`t" "hello world"
MsgBox, % RegExReplace(vText, "(?<=`t).", "$U0")

vText := "`n" "hello world"
MsgBox, % RegExReplace(vText, "(?<=`n).", "$U0")

vText := "`n`t" "hello world"
MsgBox, % RegExReplace(vText, "(?<=`n`t).", "$U0")
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 17:38

Thanks but I don't understand what this does and how it relates to the question I'm asking.

Say you are using a word processor and you start writing a new paragraph, such as "this is a new paragraph".

I'd like AHK to change this to "This is a new paragraph".
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 17:41

- So I suppose that the scripts you mentioned use hotstrings?
- You should mention which word processor. MS Word? LibreOffice Writer? Other?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 17:49

I have a AHK script that uses hotstrings and hotkeys, and I use various word processors. For instance here is the script that capitalizes the first letter of a sentence (I got it from this forum):
~.::
~!::
~?::
Input, char, L2 V C,," a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z"
Send % (ErrorLevel="Match") ? "{Backspace}+" SubStr(char,2) : ""

This works fine for sentences within a paragraph. I'd like to capitalize the beginning of the paragraph as well. Are you saying this would depend on what word program I use?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 17:57

- Your current technique depends on monitoring key presses. Theoretically detecting enter and tab key presses could give you the results you want. But for a new document for example, how could the very first character be detected.
- There *may* be some other program-specific approaches, but I haven't looked into it.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 18:09

Most well-known word processors such as MS Word capitalize the first paragraph letter. The hope was that with AHK there would be a universal way to do it for less sophisticated programs, such as Notepad for instance.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 18:43

- For Notepad, there is ControlGet with CurrentLine/CurrentCol, and if needed, ControlGetText. You could capitalise or not, based on that information.
- These principles would apply to any Edit control.
- Similar techniques of getting caret positions and text from controls or web elements may be possible.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 18:46

That looks promising. Do you have codes that do such things?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 19:30

I don't know how good this would be. It capitalises 'a' at the start of each line. I did consider using ~a::, but the CurrentCol value you get is unreliable.

Code: Select all

#IfWinActive, ahk_class Notepad
a::
ControlGet, vCol, CurrentCol,, Edit1, A
if !(vCol = 1)
{
	SendInput, {Text}a
	return
}
;SendInput, {Backspace}
SendInput, {Text}A
return
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Re: Capitalize first paragraph letter (not just after .?!)

16 Jun 2018, 19:55

The code messes up the other hotstrings that use the letter a in my script. But in Notepad it does put an A at the beginning of a paragraph starting with a, even when #IfWinActive, ahk_class Notepad is commented out. Not in the application I'm using though.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

17 Jun 2018, 14:36

Btw if you create a custom GUI with an Edit control (or perhaps other controls also), you could monitor WM_KEYDOWN messages using OnMessage, which would enable you to capitalise letters on the fly. You block certain key presses, and send alternative key presses instead.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
JPh1
Posts: 42
Joined: 18 Jan 2018, 22:06

Re: Capitalize first paragraph letter (not just after .?!)

17 Jun 2018, 15:00

Well, thanks, but I have no idea what this means. I'm using AHK to perform certain tasks while writing but I don't actually know how it works, and it doesn't look so easy to learn. So I rely on codes.

Thanks to our exchange, I see now that Capitalizing a letter following a line feed is a better way to ask my question. Perhaps I should post it that way.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Capitalize first paragraph letter (not just after .?!)

17 Jun 2018, 15:16

Add this to your original code perhaps.

Code: Select all

~Enter::
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot], peter_ahk, Ragnar, septrinus, yuu453 and 302 guests