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.
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
}
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:
And here is what it returns printed in a MsgBox: Click
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With