https://gist.github.com/endolith/876629/72084baeb622ac3dfca124cae6630703717bf01d
My prompts:
Please write me an .ahk script in the autohotkey v1 programming language. In the script, use the InputHook() function and make the script monitor for when a user accidentally starts a word with two uppercase letters. If the user does this, replace the second uppercase letter with its lowercase equivalent. However the replacement should only be made if the two uppercase letters are followed by a lowercase letter. If two uppercase letters are followed by white space, or a punctuation character, then don't do the replacement. Also, if the user types a capital letter, then removes it with Backspace and types a capital letter again, don't replace that capital letter either. Debug the script for me and make sure that there aren't any calls to nonexistent functions.
After a couple of attempts...
Thanks, this is better. There are no error messages. The script doesn't appear to be making the replacement for me, though. For example if I type, "SAmple" then it should get replaced with, "Sample." Again, the script should monitor my typing, and correct words that I accidentally type with two capital letters.
version one:
Code: Select all
#NoEnv
#Persistent
SetBatchLines -1
InputHook()
InputHook()
{
global prevChar := ""
global isUpperCase := false
InputHook_Begin:
While (hook := InputHook)
{
char := hook.Message & 0xFFFF
wParam := hook.Message >> 16
if (char == 0x08) ; Backspace
{
prevChar := ""
isUpperCase := false
}
else if (char == 0x20 || InStr(".,?!;:()", Chr(char))) ; Space or punctuation
{
prevChar := ""
isUpperCase := false
}
else if (isUpperCase)
{
if (char >= 0x61 && char <= 0x7A) ; Lowercase letter
{
if (prevChar >= 0x41 && prevChar <= 0x5A) ; Previous char is uppercase
{
SendInput {BackSpace}
SendInput % Chr(wParam + 32)
prevChar := Chr(wParam + 32)
}
else
{
prevChar := Chr(wParam)
}
isUpperCase := false
}
else
{
prevChar := ""
isUpperCase := false
}
}
else if (char >= 0x41 && char <= 0x5A) ; Uppercase letter
{
isUpperCase := true
prevChar := Chr(char)
}
else
{
prevChar := ""
isUpperCase := false
}
}
Return
}
Code: Select all
#NoEnv
#Persistent
SetBatchLines -1
InputHook()
InputHook()
{
global prevChar := ""
global isUpperCase := false
InputHook_Begin:
While (hook := InputHook)
{
char := hook.Message & 0xFFFF
wParam := hook.Message >> 16
if (char == 0x08) ; Backspace
{
prevChar := ""
isUpperCase := false
}
else if (char == 0x20 || InStr(".,?!;:()", Chr(char))) ; Space or punctuation
{
prevChar := ""
isUpperCase := false
}
else if (isUpperCase)
{
if (char >= 0x61 && char <= 0x7A) ; Lowercase letter
{
SendInput {BackSpace}
SendInput % Chr(wParam + 32)
prevChar := Chr(wParam + 32)
isUpperCase := false
}
else
{
prevChar := Chr(char)
isUpperCase := false
}
}
else if (char >= 0x41 && char <= 0x5A) ; Uppercase letter
{
isUpperCase := true
prevChar := Chr(char)
}
else
{
prevChar := ""
isUpperCase := false
}
}
Return
}