Menu Exit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mihai369
Posts: 3
Joined: 10 May 2024, 02:23

Menu Exit

10 May 2024, 02:31

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
User avatar
mikeyww
Posts: 27169
Joined: 09 Sep 2014, 18:38

Re: Menu Exit

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.
mihai369
Posts: 3
Joined: 10 May 2024, 02:23

Re: Menu Exit

11 May 2024, 06:47

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.
User avatar
mikeyww
Posts: 27169
Joined: 09 Sep 2014, 18:38

Re: Menu Exit

11 May 2024, 09:33

ChatGPT output is not permitted on this forum.
mihai369
Posts: 3
Joined: 10 May 2024, 02:23

Re: Menu Exit

12 May 2024, 06:48

mikeyww wrote:
11 May 2024, 09:33
ChatGPT output is not permitted on this forum.
Why not?
User avatar
boiler
Posts: 17191
Joined: 21 Dec 2014, 02:44

Re: Menu Exit

12 May 2024, 07:17

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Albireo, Bing [Bot], busymind, Google [Bot] and 162 guests