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
pluto007
  • Guests
  • Last active:
  • Joined: --
Hello,

i searched the forum up and down..

I would need a script which automatically corrects all words contanining
2 capitals at the beginning, e.g.

WOrd ==> Word
HOuse => House
MAnual ==> Manual
...

Is this possible? It should work in realtime... ;-)

Regards
Markus

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
It is possible (anything is possible ;) ). You will first need to separate the words. One method might be to use Loop, Parse. This will allow you to process one word at a time. Next you would need to test the second character of each word to check to see if it is Upper or Lower case (have a look at the various String functions available). One method for testing the second character could be to look up the Ascii value (Asc())of the character. If you look at an Ascii table you'll find that the upper and lower case letters are grouped together. This means that (following the table in the link) upper case letters would return a value between 65 and 90. To change the character to lower case you could use a built in function (StringLower / StringUpper)or add 32 to get the lower case equivalent.

It should work in realtime... ;-)

Could you give a bit more detail on this please? As you type? (a friend with a ruler could solve this problem a bit quicker for you if it's a bad habit ;) :twisted: ). Is the text being entered in a AutoHotkey window? (in an edit control maybe?) or in a different application?

BoBo
  • Guests
  • Last active:
  • Joined: --
Skrommel's CAPshift arbeitet in Realtime. Kaum Text selected schon konvertiert! Link bereits im Deutschen Forum geposted.

pluto007
  • Guests
  • Last active:
  • Joined: --
Hello corrupt,

here's an example:

MY name is MArkus.
..^...............^

Here you see i hold down the shift key a little bit too long, so te script should autocorrect the "MY" to "My" after pressing the space bar and should auto correct the "MArkus" to "Markus" after pressing "."

That's what I need... but I'm no scripter at all...sorry

Regards
Markus

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
I don't mind trying to put something together to help get you started :) . It would help to know where the text is being entered though. A script can be written a few different ways to detect the keys that were typed but it makes a difference where they are typed to be able to correct the keystrokes after.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Here is a case correction function:
CaseCorrect(str) {
	Loop, Parse, str, %A_Space%
		Loop, Parse, A_LoopField
			If (A_Index = 2) {
				StringLower, n, A_LoopField
				StringReplace, str, str, %x%%A_LoopField%, %x%%n%
			} Else x := A_LoopField
	Return, str
}

Example: MsgBox, % CaseCorrect("WOrd, HOuse, MAnual...")

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This script corrects double shifted characters as you type. All shifted keys on the keyboard are defined as hotkeys, which do not do anything, except if the previous hotkey was also a shifted key and less than 1 second passed. In this case the last character is removed and replaced with the un-shifted key.

It assumes, you don't have other hotkeys defined, which have + as the second character. Add your other hotkey or hotstring definitions before the Hoty label.
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
You have to change the variable "keys" for non-US keyboards.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
:shock: That's amazingly compact!

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Laszlo, :)

Thats brilliant! :D

Thanks for posting.. It is very helpful to me. :D

Regards, :)

PS: Script Showcase?
kWo4Lk1.png

pluto007
  • Guests
  • Last active:
  • Joined: --
Dear Laszlo!

Thats really brilliant! I was looking for a solution a long time!

The script is short, very fast - perfect!

Thank you very much!

Best Regards
Markus

sawfoot
  • Members
  • 3 posts
  • Last active: Mar 16 2007 09:24 PM
  • Joined: 27 Feb 2007
I couldn't get this to work - I have a non us keyboard, but don't get what changes do I make to the keys variable?
Thanks

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
You should list the characters written on the keyboard keys, to be shown when the shift key is not pressed. Hopefully, the Windows local settings are honored by AHK.

sawfoot
  • Members
  • 3 posts
  • Last active: Mar 16 2007 09:24 PM
  • Joined: 27 Feb 2007
ok, thanks. I changed them, as there were slightly difference for a UK keyboard, but the function still doesn't work. PErhaps I will just have to live without it, unless you have any other ideas...

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
What does not work? Try holding down the shift key and press another key twice, quickly, like P. What do you get in an editor, like Notepad? You should see "Pp".
You could try SendPlay or SendInput, as below.
keys = ``1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./
Loop Parse, keys
   HotKey ~+%A_LoopField%, Hoty

Hoty:
   If (SubStr(A_PriorHotKey,2,1) = "+" and A_TimeSincePriorHotkey < 999)
      SendInput % "{BS}{RAW}" SubStr(A_ThisHotKey,3,1)
Return


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Sawfoot e-mailed me his AutoCorrect script and I noticed that this topic's code wasn't in the auto-execute section. I've notified him of this.

By the way, Sawfoot sent me 900 additional misspellings, mostly based on MS Word's AutoCorrect. The topic he used to get them is jaco0646's at http://www.autohotke...opic.php?t=8057

I've included these new misspellings in the main AutoCorrect script at http://www.autohotke... ... orrect.ahk

However, I didn't include the double-cap correction from this topic here because 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.