ChatGPT trying to help me with an app using InputHook()

Talk about anything
User avatar
kunkel321
Posts: 969
Joined: 30 Nov 2015, 21:19

ChatGPT trying to help me with an app using InputHook()

Post by kunkel321 » 26 May 2023, 14:16

It's a valiant effort, but the code never works, LOL. Here are my prompts... You can see what I'm trying to do. It's actually (intended to be) similar to the "AUto-COrrect TWo COnsecutive CApitals." tool in AutoCorrect.ahk. Here:
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
}
Like I said, A valiant effort; but at this point, I don't think professional developers need to be worried. LOL
ste(phen|ve) kunkel

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: ChatGPT trying to help me with an app using InputHook()

Post by boiler » 29 May 2023, 06:18

It didn’t even use the InputHook() function. It just wrote its own function, named it InputHook(), and called it.

User avatar
xMaxrayx
Posts: 136
Joined: 06 Dec 2022, 02:56
Contact:

Re: ChatGPT trying to help me with an app using InputHook()

Post by xMaxrayx » 29 May 2023, 21:31

even if chat GPT write it correctly it wont match the pro coder because ChatGPT doesn't know anything about optimization or security.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Post Reply

Return to “Off-topic Discussion”