Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Auto-Correct 2 capital letters in a word: WOrd ==> Word


  • Please log in to reply
34 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

some people (such as programmers) might find that it interferes with their typing too much. But I'm not really sure how common that is, so comments are welcome.

This script can be made a little more intelligent. E.g. when three capitals are typed in a row, we can keep them unchanged.
keys = ``1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./

Loop Parse, keys

   HotKey ~+%A_LoopField%, Hoty



Hoty:

   CapCount := SubStr(A_PriorHotKey,2,1)="+" && A_TimeSincePriorHotkey<999 ? CapCount+1 : 1

   IfEqual CapCount,2, SendInput % "{BS}"  SubStr(A_ThisHotKey,3,1)

   IfEqual CapCount,3, SendInput % "{Left}{BS}+" SubStr(A_PriorHotKey,3,1) "{Right}"

Return
Arbitrary rules can be set, like two shifted keys, followed by a non-alphanumeric character ("US ", "KM.") they can be kept. Here we could really use key history or on_keystroke:. One could also keep his own little (dynamic) dictionary for the words with two neighbor capitals.

sawfoot
  • Members
  • 3 posts
  • Last active: Mar 16 2007 09:24 PM
  • Joined: 27 Feb 2007
All working now, great, thanks. I keep on trying to catch it out but it is always too quick for me.

Using it now the new amendment above makes sense, as you previously would have to use caps lock to type whole caps words, as holding shift wouldn't work it, so it makes it more usable. The non-alphanumeric character suggestion sounds good - preferable to a list of exclusions.
You can type things like US if you pause slightly currently - so I would recommend changing the 999ms to a lower figure - maybe around 300 from my testing.

You could always keep the improved version in, and comment it out with a note, or leave it in and allow people to comment out/delete if they wish - this would seem to be a good idea as casual users wouldn't be aware of its existence unless they delve into these forums.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I've added this to the script, but omitted autocorrection for digits and punctuation because I suspect they might do more harm than good (not sure). Also, I've made this section disabled by default because it sometimes causes unwanted corrections such as IfEqual->Ifequal. (I think a lot of people use this script, so I'm trying to avoid addihng features unless they're reasonably certain to do more good than harm for the general public.)

I also changed the style of the code to be more conventional, namely to avoid IfEqual and implicit concatenation:
;-------------------------------------------------------------------------------
; The following section auto-corrects two consecutive capital letters in a word.
; For example, "WOrd" becomes "Word".  It is disabled by default since it might
; cause unwanted corrections such as IfEqual->Ifequal.  To enable it, remove
; the /*..*/ symbols from around it.
; This section is from Laszlo's script at http://www.autohotkey.com/forum/topic9689.html
;-------------------------------------------------------------------------------
/*
; The first line of code below is the set of letters, digits, and/or symbols
; that are eligible for this type of correction.  Customize if you wish:
keys = abcdefghijklmnopqrstuvwxyz
Loop Parse, keys
	HotKey ~+%A_LoopField%, Hoty

Hoty:
	CapCount := SubStr(A_PriorHotKey,2,1)="+" && A_TimeSincePriorHotkey<999 ? CapCount+1 : 1
	if CapCount = 2
		SendInput % "{BS}" . SubStr(A_ThisHotKey,3,1)
	else if CapCount = 3
		SendInput % "{Left}{BS}+" . SubStr(A_PriorHotKey,3,1) . "{Right}"
Return
*/

Refinements are welcome. Thanks for the script.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Handling some CamelCase words (like IfEqual) can be easily accomplished with a dummy hotkey, like
~Shift Up::Return
It will change A_PriorHotKey, so the counting restarts at the next capital letter.

It is a good idea to exclude certain shifted keys, which are often duplicated: ##, &&, **, __, ++, ||, <<, >>. Others could remain.

In case of Ms Word, excluding ~, # looks necessary. For some unknown reasons, sometimes, after a space, they result in some extra or unexplained characters in the text. I did not experience this in other applications.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
If you want to leave two capitals alone if they are followed by an un-shifted punctuation mark, try adding the following hotkeys to the script.
~Shift Up::      ; handle CamelCase
   key0 := SubStr(A_PriorHotKey,2,1)="+" && A_TimeSincePriorHotkey<999 && CapCount=2
           ? SubStr(A_PriorHotKey,3,1) : ""
Return

~.::
~,::
~'::
~"::
~-::
   If (key0 <> "" && A_PriorHotKey = "~Shift Up" && A_TimeSincePriorHotkey<999)
      SendInput % "{Left}{BS}+" key0 "{Right}"
Return
At Shift Up we check if the previous key was changed to lower case, within the last second. If yes, we save the changed key in the variable key0. The handled punctuation marks always come after a Shift Up. If not more than one second passed, we can correct key0 back to capital.

Of course, such simple scripts cannot be foolproof. If you move the insertion point or the active window changes within the critical second, the correction appears at the wrong place. We ought to know it, or if other keys were pressed. With proper key history we could remove the timing restrictions.

sunil kanta swain
  • Guests
  • Last active:
  • Joined: --
Hello,

i searched for permanently delete autocorrect from ms word.could u kindly to help me out for this kind of problem ?

Regards
sunil kanta swain,
system administration,
C Bay Systems (India) Pvt ltd,
Bangalore 560008
mail ID:sunilkanta033@gmail.com /sunil_swain37@yahoo.co.in

sunil kanta swain
  • Guests
  • Last active:
  • Joined: --

Hello,

i searched for permanently delete autocorrect from ms word.could u kindly to help me out for this kind of problem ?mail methe solution asap.

Regards
sunil kanta swain,
system administration,
C Bay Systems (India) Pvt ltd,
Bangalore 560008
mail ID:sunilkanta033@gmail.com /sunil_swain37@yahoo.co.in



chgoguy7
  • Members
  • 2 posts
  • Last active: Mar 09 2009 04:08 PM
  • Joined: 22 Feb 2009
Laszlo,

I have found that this script also applies to two letter acronyms which should occasionally remain capitalized such as AM, PM, TV, etc. I know it would break the script from correcting such errors as "MY book" but I think I would prefer that. Is there a check that I could add to the script for two letter strings that leaves both letters capitalized?

Thanks!

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Add ~Space to the hotkeys monitoring 2 capitals:
keys = ``1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./
Loop Parse, keys
   HotKey ~+%A_LoopField%, Hoty        ; Shifted keys to monitor

keys = 1234567890qwertyuiopasdfghjklzxcvbnm
Loop Parse, keys
   HotKey ~%A_LoopField%, Normal       ; Unshifted keys to register as hotkeys

keys = ``-=[]\;',./
Loop Parse, keys
   HotKey ~%A_LoopField%, ~Space       ; Special chars to keep 2 capitals before

Hoty:
   CapCount := SubStr(A_PriorHotKey,2,1)="+" && A_TimeSincePriorHotkey<999 ? CapCount+1 : 1
   IfEqual CapCount,2, SendInput % "{BS}{"  SubStr(A_ThisHotKey,3,1) "}"
   IfEqual CapCount,3, SendInput % "{Left}{BS}+{" SubStr(A_PriorHotKey,3) "}{Right}"
Normal:
Return

~Shift Up::                            ; Handle CamelCase
   key0 := SubStr(A_PriorHotKey,2,1)="+" && A_TimeSincePriorHotkey<999 && CapCount=2
           ? SubStr(A_PriorHotKey,3) : ""
Return

~Space::                               ; Restore 2 capitals before special chars
   If (key0 <> "" && A_PriorHotKey = "~Shift Up" && A_TimeSincePriorHotkey<999)
      SendInput % "{Left}{BS}+{" key0 "}{Right}"
Return
Now, if you type "AM"{Space} the M remains capitalized. Similar to "AM."

Edit 20090223: Bugfix, regular keys restart counting

chgoguy7
  • Members
  • 2 posts
  • Last active: Mar 09 2009 04:08 PM
  • Joined: 22 Feb 2009
Hi Laszlo,

Thanks for the quick response! Much appreciated. There appears to be a problem with the new script though. When compiling the script I receive the following error message:

Note: The hotkey H~.:: will not be active because it does not exist in the current keyboard layout.

Also, and maybe this is related to the above error, if I type DId [space] it changes to DiI.

Again, thanks so much for helping me out with this. If you might be able to take another look at the script when you have a minute I would really appreciate it. Thanks!!! :D

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I don't get compile errors. Maybe there was a copy-paste problem?

But, you are right. There was a bug in the script. I corrected it in my previous post. I don't have time to test it, so please report further bugs.

ahknice
  • Guests
  • Last active:
  • Joined: --
Lazlo I tried this and it worked well. Now I tried to integrate it to my ahk and now it doesn't work. Help.

keys = ``1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./
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 < 999)
      Send {BS}%c1%
Return


ahknice
  • Guests
  • Last active:
  • Joined: --
I tried putting it on top, right below the password, in the middle and in the end, all the same doesn't work. Help me understand how this works.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
The first 3 lines belong to the auto-execute section of the script (top), the Hoty subroutine has to be in the end.

ahknice
  • Guests
  • Last active:
  • Joined: --
Thanks Lazlo for the quick response. Works perfect now. :p