REvert TWo CApital LEtters

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

REvert TWo CApital LEtters

02 Feb 2024, 15:47

Hi, noob here.
Could someone help me write a script that would change...
upper-case letter, upper-case letter, lower-case letter
into...
upper-case letter, lower-case letter, lower-case letter
Thanks!
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

Re: REvert TWo CApital LEtters

02 Feb 2024, 16:57

@rommmcek
Yeah that's great, thanks.
ntepa's v2 code works like a charm.

I should say to anyone testing it though who may make the same mistake I did:
If you're testing it, you can't test it slowly,
because it's deliberately written to not work if you take more than 0.4 seconds.
But yeah, great help!
Thanks again!
User avatar
kunkel321
Posts: 1141
Joined: 30 Nov 2015, 21:19

Re: REvert TWo CApital LEtters

03 Feb 2024, 17:43

robinson wrote:
02 Feb 2024, 16:57
...because it's deliberately written to not work if you take more than 0.4 seconds.
You can temporarily remove the T.4, for testing purposes.
ste(phen|ve) kunkel
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

Re: REvert TWo CApital LEtters

04 Feb 2024, 10:50

@ntepa
Actually one thing I noticed about this script, is that it doesn't just do this:
EXample ---> Example
but it also does this, which occasionally causes inconvenience for me:
EXAmple ---> EXample

Is it possible to change this functionality? I don't think it would ever be useful.
User avatar
kunkel321
Posts: 1141
Joined: 30 Nov 2015, 21:19

Re: REvert TWo CApital LEtters

04 Feb 2024, 12:07

I think this might do the trick(?)
-haven't thoroughly tested
-ntepa might have a better way to do it.

EDIT: Upon further testing.... Some relevant points:
-The hotstring is any two UPPERcase letters.
-The Z hotstring option causes the hotstring to reset each time. So without the Z, if you type ABCdef, then AB is a trigger, but BC is also a trigger. When the Z is used, BC is no longer a trigger. However, if you type ABCDef then AB is a trigger and CD (which is the next set of 2 caps), is also a trigger. So if you type ABCDef you get ---> ABCdef

EDIT 2: After even more testing... The extra IF statement that I put in the InputHook part doesn't even do anything. :facepalm: The Z option is the only thing that makes a difference between the below code and ntepa's original.

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+
;------------------------------------------------------------------------------
;#NoTrayIcon
TraySetIcon('imageres.dll', 256) ; An "undo" icon
;------------------------------------------------------------------------------
;       AUto-COrrect TWo COnsecutive CApitals
; This version by forum user Ntepa. Updated 8-7-2023.
; https://www.autohotkey.com/boards/viewtopic.php?p=533067#p533067
; Tweaked by kunkel321 2-4-2024
;------------------------------------------------------------------------------

; NOTE:  Read above edits. 

fix_consecutive_caps()
fix_consecutive_caps() {
; Hotstring only works if CapsLock is off.
	HotIf (*) => !GetKeyState("CapsLock", "T")
	loop 26 {
		char1 := Chr(A_Index + 64)
		loop 26 {
			char2 := Chr(A_Index + 64)
			; Create hotstring for every possible combination of two letter capital letters.
			Hotstring(":*?CXB0Z:" char1 char2, fix.Bind(char1, char2)) ; <--- added Z here
		}
	}
	HotIf
	; Third letter is checked using InputHook.
  fix(char1, char2, *) {
    ih := InputHook("V I101 L1" ) ; T.3") <--- timeout removed for debugging.
    ih.OnEnd := OnEnd
    ih.Start()
    OnEnd(ih) {
		char3 := ih.Input
		if (char3 ~= "[A-Z]")  ; If char is UPPERcase alpha.  <--- added 2-4-2024
			ih.Stop()
		else if (char3 ~= "[a-z]")  ; If char is lowercase alpha.
		|| (char3 = A_Space && char1 char2 ~= "OF|TO|IN|IT|IS|AS|AT|WE|HE|BY|ON|BE|NO") {
			SendInput("{BS 2}" StrLower(char2) char3)
		}
		}
	}
}
ste(phen|ve) kunkel
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

Re: REvert TWo CApital LEtters

05 Feb 2024, 16:56

@kunkel321
This one results in double input (inputted? inpat?) letters too often.

Image
User avatar
kunkel321
Posts: 1141
Joined: 30 Nov 2015, 21:19

Re: REvert TWo CApital LEtters

06 Feb 2024, 08:29

robinson wrote:
05 Feb 2024, 16:56
@kunkel321
This one results in double input (inputted? inpat?) letters too often.
Image
That can't be right... Is it possible that you accidentally have two versions (and instances) of the script running at the same time? Check how many green H icons are in your Systray... (Or check for the blue 'back arrow' icon, if you are using that.)
ste(phen|ve) kunkel
User avatar
kunkel321
Posts: 1141
Joined: 30 Nov 2015, 21:19

Re: REvert TWo CApital LEtters

07 Feb 2024, 08:57

I think this one might fix it... Try it. It changes
AAaaaaa ---> Aaaaaaa
but leaves
AAAaaaa ---> AAAaaaa
AAAAaaa ---> AAAAaaa
AAAAAaa ---> AAAAAaa

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+
;------------------------------------------------------------------------------
;#NoTrayIcon
TraySetIcon('imageres.dll', 256) ; An "undo" icon
;------------------------------------------------------------------------------
;       AUto-COrrect TWo COnsecutive CApitals
; This version by forum user Ntepa. Updated 8-7-2023.
; https://www.autohotkey.com/boards/viewtopic.php?p=533067#p533067
; Tweaked by kunkel321 2-7-2024
;------------------------------------------------------------------------------

fix_consecutive_caps()
fix_consecutive_caps() {
; Hotstring only works if CapsLock is off.
	HotIf (*) => !GetKeyState("CapsLock", "T")
	loop 26 {
		char1 := Chr(A_Index + 64)
		loop 26 {
			char2 := Chr(A_Index + 64)
			; Create hotstring for every possible combination of two letter capital letters.
			Hotstring(":*?CXB0Z:" char1 char2, fix.Bind(char1, char2)) 
		}
	}
	HotIf
	; Third letter is checked using InputHook.
  fix(char1, char2, *) {
    ih := InputHook("V I101 L1" ) ; T.3") <--- timeout removed for debugging.
    ih.OnEnd := OnEnd
    ih.Start()
    OnEnd(ih) {
		char3 := ih.Input
		if (char3 ~= "[A-Z]")  ; If char is UPPERcase alpha.
			Hotstring "Reset"
		else if (char3 ~= "[a-z]")  ; If char is lowercase alpha.
		|| (char3 = A_Space && char1 char2 ~= "OF|TO|IN|IT|IS|AS|AT|WE|HE|BY|ON|BE|NO") {
			SendInput("{BS 2}" StrLower(char2) char3)
		}
		}
	}
}
ste(phen|ve) kunkel
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

Re: REvert TWo CApital LEtters

07 Feb 2024, 10:46

@kunkel321
Uh... yes. That is indeed totally possible. You might even say, more than possible..
...
OK yeah there were two running at the same time.
But I found another issue!
Sometimes I just want to hold down shift and type a few words out in all caps,
not lifting my pinky off shift until I've finished writing out the last word,
but in that case it does this:
THIS IS JUST A TEST ---> THIS Is JUST A TEST
Image
Any idea why that's happening?
User avatar
kunkel321
Posts: 1141
Joined: 30 Nov 2015, 21:19

Re: REvert TWo CApital LEtters

07 Feb 2024, 15:39

robinson wrote:
07 Feb 2024, 10:46
THIS IS JUST A TEST ---> THIS Is JUST A TEST
Actually that's intentional! There are several common two-letter words in the RegEx part of this line of code:

Code: Select all

|| (char3 = A_Space && char1 char2 ~= "OF|TO|IN|IT|IS|AS|AT|WE|HE|BY|ON|BE|NO") 
Ntepa added those for us so that they would get corrected AA --> Aa even though they don't conform to the Upper Upper Lower rule. You can get rid of that functionality by removing that part of the code. Be sure to remove the || but don't remove the brace { at the end of the line.
ste(phen|ve) kunkel
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

Re: REvert TWo CApital LEtters

07 Feb 2024, 18:16

@kunkel321
I guess that's the issue closed then!
Thanks for your help!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: TAC109 and 37 guests