Page 1 of 1

How to correct DOuble CApitalization, allow TrIPPLE capitalization.

Posted: 29 Nov 2019, 17:36
by Vladimir
This is a code for DUal CApitalization correction.

Code: Select all

; Removes DOuble CApitalization - adjust timer to improve precision
;keys = ``1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./
keys = qwertyuiopasdfghjklzxcvbnm
Loop Parse, keys
   HotKey ~+%A_LoopField%, Hoty

Hoty:
   StringMid c0, A_PriorHotKey,2, 1
   StringMid c1, A_ThisHotKey, 3, 1
   If (c0 = "+" and A_TimeSincePriorHotkey < 250)
      Send {BS}%c1%
Return
This is a code for DUal CApitalization correction.

I believe that this code could work much better if it would consider that if I keep holding the shift key, after seeing a correction made, I am probably typing a short abbreviation in ALL CAPS.
How can I change this code so it would correct dual capitalization, yet if I type in a word, and it comes out like ThIS, the lowercase h needs to be replaced with the upper case?

Thank you.

Re: How to correct DOuble CApitalization, allow TrIPPLE capitalization.

Posted: 29 Nov 2019, 23:01
by fwejifjjwk2
After finish all article use Regular replace?

Re: How to correct DOuble CApitalization, allow TrIPPLE capitalization.

Posted: 07 Dec 2019, 09:52
by Vladimir
I can use replace, however
I am trying to understand the confusing syntax of AutoHotKey with this example.
There are so many standard functions that use such inconsistent syntax that sometimes I cannot read the code.

Re: How to correct DOuble CApitalization, allow TrIPPLE capitalization.

Posted: 07 Dec 2019, 20:11
by boiler
See the comment after each line below for a description of what it does:

Code: Select all

keys = qwertyuiopasdfghjklzxcvbnm ; adds all 26 letters to a string
Loop Parse, keys ; loops through each letter one at a time
   HotKey ~+%A_LoopField%, Hoty ; creates a hotkey of the shifted version (+) of each letter; the ~ allows the key to be sent through as it is typed

Hoty: ; this is the label that is invoked by each of the 26 hotkeys
   StringMid c0, A_PriorHotKey,2, 1 ; isolates the 2nd character of the previous hotkey and assigns it to variable c0 so it can be checked to see if it is + (meaning shifted)
   StringMid c1, A_ThisHotKey, 3, 1 ; isolates the 3rd character of the current hotkey and assigns it to variable c1 so it can be sent without being shifted if desired
   If (c0 = "+" and A_TimeSincePriorHotkey < 250) ; checks to see if the prior hotkey was shifted and if it occured within the last 250 msec (0.25 seconds)
      Send {BS}%c1% ; if the above is true, then backspace over the last character sent and re-send it in its non-shifted form
Return ; return from the hotkey subroutine