AutoHotKey: InputBox with multi-line input

In AutoHotKey, I want to have something like an InputBox, except that text input is multi-line. (i.e. as a text box).

I want me to have two buttons: OK and Cancel, and I want both of them to have accelerators. I want this code to be in the form of a function that I can call from other keyboard shortcuts to get multi-line user input whenever I want. I want to be able to set the default text displayed when the dialog is displayed. I want the function to return a blank or empty string if the cancel button was pressed. I want the Esc key to close the dialog box, as if the cancel button had been pressed (and not exit the whole script). I want the dialog box to appear in the center of the screen and use the font that Windows usually uses for dialogs.

+5
source share
4 answers

try it

!1::
MsgBox % MultiLineInputBox("Hello World:", "stuff, more stuff", "Custom Caption")
return
MultiLineInputBox(Text:="", Default:="", Caption:="Multi Line Input Box"){ static ButtonOK:=ButtonCancel:= false if !MultiLineInputBoxGui{ Gui, MultiLineInputBox: add, Text, r1 w600 , % Text Gui, MultiLineInputBox: add, Edit, r10 w600 vMultiLineInputBox, % Default Gui, MultiLineInputBox: add, Button, w60 gMultiLineInputBoxOK , &OK Gui, MultiLineInputBox: add, Button, w60 x+10 gMultiLineInputBoxCancel, &Cancel MultiLineInputBoxGui := true } GuiControl,MultiLineInputBox:, MultiLineInputBox, % Default Gui, MultiLineInputBox: Show,, % Caption SendMessage, 0xB1, 0, -1, Edit1, A while !(ButtonOK||ButtonCancel) continue if ButtonCancel return Gui, MultiLineInputBox: Submit, NoHide Gui, MultiLineInputBox: Cancel return MultiLineInputBox ;---------------------- MultiLineInputBoxOK: ButtonOK:= true return ;---------------------- MultiLineInputBoxGuiEscape: MultiLineInputBoxCancel: ButtonCancel:= true Gui, MultiLineInputBox: Cancel return }
+5
source

You can keep it pretty short:
(tested and working)

MultiLineInput(Text:="Waiting for Input") {
    Global MLI_Edit
    Gui, Add, Edit, vMLI_Edit x2 y2 w396 r4
    Gui, Add, Button, gMLI_OK x1 y63 w199 h30, &OK
    Gui, Add, Button, gMLI_Cancel x200 y63 w199 h30, &Cancel
    Gui, Show, h94 w400, %Text%
    Goto, MLI_Wait
    MLI_OK:
        GuiControlGet, MLI_Edit
    MLI_Cancel:
    GuiEscape:
        ReturnNow := True
    MLI_Wait:
        While (!ReturnNow)
            Sleep, 100
    Gui, Destroy
    Return %MLI_Edit%
}

MsgBox % MultiLineInput("Tell me 5 things you like.")

This is what it might look like:
enter image description here

And here is what returns to MsgBox: Click

+1
source

fooobar.com/questions/1555585/... , - , :

MultiLineInputBox(Text:="", Default:="", Caption:="Multi Line Input Box")
{
    static
    ButtonOK:=ButtonCancel:= false
    Gui GuiMLIB:New,, % Caption
    Gui, add, Text, w600, % Text
    Gui, add, Edit, r10 w600 vMLIBEdit, % Default
    Gui, add, Button, w60 gMLIBOK , &OK
    Gui, add, Button, w60 x+10 gMLIBCancel, &Cancel

    Gui, Show
    while !(ButtonOK||ButtonCancel)
        continue
    if ButtonCancel
        return
    Gui, Submit
    return MLIBEdit
    ;----------------------
    MLIBOK:
    ButtonOK:= true
    return
    ;---------------------- 
    GuiMLIBGuiEscape:
    GuiMLIBGuiClose:
    MLIBCancel:
    ButtonCancel:= true
    Gui, Cancel
    return
}
+1

:

1 ( Gosub):

return
StartGui:
Gui, Add, Edit, x22 y19 w240 h120 vMyEdit, Here is default text
Gui, Add, Button, x22 y179 w100 h30 gGuiCloseOk, Ok
Gui, Add, Button, x162 y179 w100 h30 gGuiCloseCancel, Cancel
; Generated using SmartGUI Creator for SciTE
Gui, Show, w286 h231, My Gui Name

WinGetPos,,, Width, Height, My Gui Name
WinMove, My Gui Name,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)

return

return
GuiCloseOK:
GuiControlGet, MyEdit
Gui, Destroy
return

GuiCloseCancel:
MyEdit:=""
Gui, Destroy
return


return
Esc::
Gui, Destroy
return

script . , Gosub, StartGui. Edit MyEdit.

, GUI CTRL + ALT + z, script :

return
!^z::
    Gosub, StartGui
return




2 ( ):

GuiFunc(DefaultText)
{
    global MyEdit
    MyEdit:=""
    Gui, Add, Edit, x22 y19 w240 h120 vMyEdit, %DefaultText%
    Gui, Add, Button, x22 y179 w100 h30 gGuiCloseOk, &Ok
    Gui, Add, Button, x162 y179 w100 h30 gGuiCloseCancel, &Cancel
    ; Generated using SmartGUI Creator for SciTE
    Gui, Show, w286 h231, My Gui Name

    WinGetPos,,, Width, Height, My Gui Name
    WinMove, My Gui Name,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)

    return

    return
    GuiCloseOK:
    GuiControlGet, MyEdit
    Gui, Destroy
    return

    GuiCloseCancel:
    MyEdit:=""
    Gui, Destroy
    return

}


return
Esc::
    Gui, Destroy
return

script . GUI, GuiFunc(DefaultText) , Edit. MyEdit Edit. , MyEdit . , , MyEdit, .

, script . GUI CTRL + ALT + z MyEdit CTRL + ALT + a:

return
!^z::
    DefaultText:= "Here is default text"
    GuiFunc(DefaultText)
return

return
!^a::
    MsgBox, %MyEdit%
return



, Window Title My Gui Name, , 3- script .

, AutoHotkey http://ahkscript.org/ ( uptodate, )! AutoHotkey autohotkey.com , !

0

All Articles