AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Auto-Correct 2 capital letters in a word: WOrd ==> Word
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Thu Mar 01, 2007 12:10 am    Post subject: Reply with quote

Chris wrote:
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.
Code:
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.
Back to top
View user's profile Send private message
sawfoot



Joined: 27 Feb 2007
Posts: 3

PostPosted: Thu Mar 01, 2007 12:14 am    Post subject: sawfoot Reply with quote

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.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10667

PostPosted: Thu Mar 01, 2007 2:04 am    Post subject: Reply with quote

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:
Code:
;-------------------------------------------------------------------------------
; 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.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Thu Mar 01, 2007 2:58 am    Post subject: Reply with quote

Handling some CamelCase words (like IfEqual) can be easily accomplished with a dummy hotkey, like
Code:
~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.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Thu Mar 01, 2007 3:58 am    Post subject: Reply with quote

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.
Code:
~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.
Back to top
View user's profile Send private message
sunil kanta swain
Guest





PostPosted: Fri May 02, 2008 9:31 am    Post subject: sub:how to permanently delete autocorrect from the ms word Reply with quote

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
Back to top
sunil kanta swain
Guest





PostPosted: Fri May 02, 2008 9:33 am    Post subject: Re: sub:how to permanently delete autocorrect from the ms wo Reply with quote

sunil kanta swain wrote:
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
Back to top
chgoguy7



Joined: 23 Feb 2009
Posts: 2

PostPosted: Mon Feb 23, 2009 12:32 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Mon Feb 23, 2009 1:33 am    Post subject: Reply with quote

Add ~Space to the hotkeys monitoring 2 capitals:
Code:
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


Last edited by Laszlo on Mon Feb 23, 2009 7:25 am; edited 1 time in total
Back to top
View user's profile Send private message
chgoguy7



Joined: 23 Feb 2009
Posts: 2

PostPosted: Mon Feb 23, 2009 2:00 am    Post subject: Reply with quote

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!!! Very Happy
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Mon Feb 23, 2009 7:30 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ahknice
Guest





PostPosted: Mon Mar 09, 2009 7:36 am    Post subject: Reply with quote

Lazlo I tried this and it worked well. Now I tried to integrate it to my ahk and now it doesn't work. Help.

Code:

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
Back to top
ahknice
Guest





PostPosted: Mon Mar 09, 2009 7:39 am    Post subject: Reply with quote

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.
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Mon Mar 09, 2009 3:28 pm    Post subject: Reply with quote

The first 3 lines belong to the auto-execute section of the script (top), the Hoty subroutine has to be in the end.
Back to top
View user's profile Send private message
ahknice
Guest





PostPosted: Wed Mar 11, 2009 1:30 am    Post subject: Reply with quote

Thanks Lazlo for the quick response. Works perfect now. Razz
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group