Page 1 of 1

Menu Exit

Posted: 10 May 2024, 02:31
by mihai369
Hello! I have this script. I don't know for sure if it's in Autohotkey v1 or v2.
The code does this: When I press LShift and write 3 letters, a menu appears to select one of the options starting with those 3 letters. The menu closes only if I choose an option or press Enter.
What I want is this: If I don`t like any option from the menu to be able to continue writing where the cursor is, automatically closing the menu without pressing enter.
I tried everything, but in vain.
Can anyone help me with this?

Code: Select all

#Persistent
SendMode, Event

creditori := "LANGOS|MARTE|MARATHON"
SugestiiMenuExist := 0
SugestiiMenuVisible := 0

MenuExist() {
    return SugestiiMenuExist
}

MenuVisible() {
    return SugestiiMenuVisible
}

~LShift::
    sugestiiCount := 0
    userInput := ""
    Input, userInput, L3 V
    if (SugestiiMenuExist)
    {
        Menu, SugestiiMenu, DeleteAll
    }
    else
    {
        SugestiiMenuExist := 1
        Menu, SugestiiMenu, Add
    }

    hasLowerCase := 0

    Loop, Parse, userInput
    {
        if (Asc(A_LoopField) >= 97 && Asc(A_LoopField) <= 122)
        {
            hasLowerCase := 1
            break
        }
    }

    if (!hasLowerCase)
    {
        Loop, Parse, creditori, | 
        {
            if (SubStr(A_LoopField, 1, 3) = userInput)
            {
                sugestiiCount++
                sugestie := sugestiiCount ". " A_LoopField
                Menu, SugestiiMenu, Add, % sugestie, SelectCreditor
            }
        }

        if (sugestiiCount > 0)
        {
            SugestiiMenuVisible := 1
            Menu, SugestiiMenu, Show
        }
        else
        {
            SugestiiMenuVisible := 0
        }
    }
return

SelectCreditor:
    creditorSelectat := A_ThisMenuItem
    creditor := SubStr(creditorSelectat, InStr(creditorSelectat, ". ") + 2)
    Send, % SubStr(creditor, 4)
    Clipboard := creditor
    Send {Tab 3}
return

if (SugestiiMenuVisible)
{
    Menu, SugestiiMenu, Show
    GoSub, SelectCreditor      
}
return

Re: Menu Exit

Posted: 10 May 2024, 08:31
by mikeyww
Welcome to this AutoHotkey forum!

Does the script work? Is it a ChatGPT special, or came from elsewhere?

You could test whether SetTimer would work to reload the script when the menu is displayed. I did not test it.

The final code block would never execute since it follows a Return command, right? The code is unreachable.

Re: Menu Exit

Posted: 11 May 2024, 06:47
by mihai369
mikeyww wrote:
10 May 2024, 08:31
Welcome to this AutoHotkey forum!

Does the script work? Is it a ChatGPT special, or came from elsewhere?

You could test whether SetTimer would work to reload the script when the menu is displayed. I did not test it.

The final code block would never execute since it follows a Return command, right? The code is unreachable.
Hello! The script works fine. I wrote it with a little help from ChatGPT. I really don`t think a timer can be useful in this case.

Re: Menu Exit

Posted: 11 May 2024, 09:33
by mikeyww
ChatGPT output is not permitted on this forum.

Re: Menu Exit

Posted: 12 May 2024, 06:48
by mihai369
mikeyww wrote:
11 May 2024, 09:33
ChatGPT output is not permitted on this forum.
Why not?

Re: Menu Exit

Posted: 12 May 2024, 07:17
by boiler
Because much more often than not, it writes nonsensical code, and it’s a waste of time for the forum members to bother trying to unravel it. See the Forum Rules.