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.
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)
}
}
}
}