| View previous topic :: View next topic |
| Author |
Message |
pluto007 Guest
|
Posted: Sun May 07, 2006 9:09 pm Post subject: Auto-Correct 2 capital letters in a word: WOrd ==> Word |
|
|
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 |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2391
|
Posted: Sun May 07, 2006 9:38 pm Post subject: |
|
|
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.
| Quote: | 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 ). Is the text being entered in a AutoHotkey window? (in an edit control maybe?) or in a different application?
Last edited by corrupt on Sun May 07, 2006 9:41 pm; edited 1 time in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Sun May 07, 2006 9:38 pm Post subject: |
|
|
| Skrommel's CAPshift arbeitet in Realtime. Kaum Text selected schon konvertiert! Link bereits im Deutschen Forum geposted. |
|
| Back to top |
|
 |
pluto007 Guest
|
Posted: Sun May 07, 2006 9:53 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2391
|
Posted: Sun May 07, 2006 10:00 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5026 Location: imaginationland
|
Posted: Sun May 07, 2006 10:52 pm Post subject: |
|
|
Here is a case correction function: | Code: | 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...") _________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3959 Location: Pittsburgh
|
Posted: Sun May 07, 2006 11:48 pm Post subject: |
|
|
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. | 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 | You have to change the variable "keys" for non-US keyboards. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Mon May 08, 2006 2:42 am Post subject: |
|
|
That's amazingly compact! |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5723
|
Posted: Mon May 08, 2006 5:16 am Post subject: |
|
|
Dear Laszlo,
Thats brilliant!
Thanks for posting.. It is very helpful to me.
Regards,
PS: Script Showcase? _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
pluto007 Guest
|
Posted: Mon May 08, 2006 9:49 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
sawfoot
Joined: 27 Feb 2007 Posts: 3
|
Posted: Tue Feb 27, 2007 7:34 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3959 Location: Pittsburgh
|
Posted: Wed Feb 28, 2007 5:20 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
sawfoot
Joined: 27 Feb 2007 Posts: 3
|
Posted: Wed Feb 28, 2007 2:51 pm Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3959 Location: Pittsburgh
|
Posted: Wed Feb 28, 2007 3:45 pm Post subject: |
|
|
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. | Code: | 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 |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Feb 28, 2007 11:26 pm Post subject: |
|
|
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.autohotkey.com/forum/viewtopic.php?t=8057
I've included these new misspellings in the main AutoCorrect script at http://www.autohotkey.com/download/wikipedia_autocorrect.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. |
|
| Back to top |
|
 |
|