How to Use Enter to Select From Drop Down List Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

How to Use Enter to Select From Drop Down List

26 Apr 2017, 17:36

A few simple questions I have about this:

*** Is there a way to make it select from receiving the Enter key for whichever option is highlighted, rather than using a button?

Is it possible to remove the window buttons, minimize, maximize and close?

Is it possible to have a blank title for the window, such that it doesn't say the file name?

Haven't found the answer yet here: https://www.autohotkey.com/docs/command ... ntrols.htm. Will continue to browse in the meantime.

Code: Select all

^!.::

Gui Add, ListBox, vOPTION x15 y17 w100, 1||2|3
Gui Show, w130 h75,  ; title goes here but how do I make it blank?
Sleep 1000

GetListBoxValue:
    Gui Submit
    MsgBox %OPTION%

Return
Why do I get an error if I try to run it a second time?


Thanks
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: How to Use Enter to Select From Drop Down List

26 Apr 2017, 18:47

Code: Select all

Gui -SysMenu
Gui Add, ListBox, vOPTION x15 y17 w100, 1||2|3
Gui Show, w130 h75, %A_Space%

OnMessage(0x100, "OnWM_KEYDOWN")
Return

GuiEscape:
    ExitApp

GetListBoxValue:
    Gui Submit, NoHide
    MsgBox %OPTION%
Return

OnWM_KEYDOWN(wParam, lParam, msg, hWnd) {
    If (wParam == 13) {
        GoSub GetListBoxValue
    }
}
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: How to Use Enter to Select From Drop Down List

26 Apr 2017, 18:55

Thank you, I appreciate this script.

Does gui need to ExitApp in order to close the gui window?

I'd like the window to be gone after the message box appears but with code following it, and part of a hotkey that can be used repeatedly.

I've noticed if you take away NoHide, it goes away, but then the script can be called again. It gets an error the second time around.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: How to Use Enter to Select From Drop Down List  Topic is solved

26 Apr 2017, 19:36

Hi magicinmath,
magicinmath wrote:Is it possible to remove the window buttons, minimize, maximize and close?

Code: Select all

Gui +Resize -SysMenu ; -MinimizeBox -MaximizeBox ; uncomment both last options if you don't want the window to be minimizable/maximizable (pressing Windows+Down/Up)
magicinmath wrote:Does gui need to ExitApp in order to close the gui window?
No. See especially Gui, Destroy command:

Code: Select all

Gui, destroy
magicinmath wrote:Why do I get an error if I try to run it a second time?
Your hotkey add a ListBox with the OPTION associated output variable without having destroying it before, yet the same variable cannot be used for more than one control. Use instead:

Code: Select all

Gui Submit
Gui, destroy
...or put this line:

Code: Select all

Gui Add, ListBox, vOPTION x15 y17 w100, 1||2|3
above your hotkey; this way your hotkey will only shows again the gui, not recreating each time the same control.



Also, if you intend to have a more complex gui, with other controls, you should check whether or not your listbox is actually the focused control before lunching the GetListBoxValue label on Enter key press.

Code: Select all

OnWM_KEYDOWN(wParam, lParam, msg, hWnd) {
    If (wParam == 13) {
	GuiControlGet, focusedControl, Focus
	if (focusedControl == "ListBox1")
        GoSub GetListBoxValue
    }
}

Hope this helps.


EDIT: Or you can do it even more easely using the +Default button option:

Code: Select all

Gui, Add, Edit, w200, test
Gui Add, ListBox, vOPTION x45 y70 w100, 1||2|3
Gui, Add, Button, +Default gGetListBoxValue x-10 y-10 w5 h5, ; +/-Default. Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option.
!i::
Gui -SysMenu
Gui Show, AutoSize, %A_Space%
return

GetListBoxValue:
GuiControlGet, focusedControl, Focus
	if (focusedControl == "ListBox1")
	{
    Gui Submit
	; Gui, Destroy
    MsgBox %OPTION%
    }
return
my scripts
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: How to Use Enter to Select From Drop Down List

26 Apr 2017, 21:27

Thanks everyone, both answers were great and I learned a lot! Much appreciated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: -Elaphe-, downstairs, Google [Bot], sebalotek and 197 guests