Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoHotKey: InputBox with multiline input

In AutoHotKey, I want to have something like InputBox except that the text input is multiline. (i.e. like a textarea).

I want there to be two buttons, "Ok" and "Cancel", and I want them both to have accelerators. I want this code to be in the form of a function that I can call from other hotkeys to get multiline user input whenever I want. I want to be able to set the default text shown when the dialog is shown. I want the function to return null or empty string if the cancel button was pressed. I want the Esc key to cause the dialog to be closed as if the cancel button was pressed (and not exit the entire script). I want the dialog to show in the center of the screen, and to use the font that Windows usually uses for dialogs.

like image 999
Ram Rachum Avatar asked Sep 08 '14 11:09

Ram Rachum


2 Answers

try this

!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 }
like image 183
alpha bravo Avatar answered Sep 24 '22 13:09

alpha bravo


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

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 could look like:
enter image description here

And here is what it returns printed in a MsgBox: Click

like image 30
Forivin Avatar answered Sep 22 '22 13:09

Forivin