Multiline input

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Multiline input

Post by lionpack » 27 Jul 2023, 14:49

Hi,

How do I make the InputBox, UserInput multiline?

Thank you!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 27 Jul 2023, 15:30

You can create a custom GUI with an Edit control as the input field. Here is a customizable InputBox you could use directly, but it doesn't have to be that complicated.

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 27 Jul 2023, 15:47

Try this:

Code: Select all

MsgBox, % InputBoxML("Enter your address:", "Address", 3)
return

InputBoxML(prompt="", title="", rows=2, width=200) {
	static IbmlEntry
	Gui, IBML:+ToolWindow +hwndIbmlID
	Gui, IBML:Add, Text,, % prompt
	Gui, IBML:Add, Edit, % "vIbmlEntry xm r" rows " w" width
	Gui, IBML:Add, Button, % "gIbmlSubmit xm+" width/2-25 " w50", Submit
	Gui, IBML:Show,, % title
	
	WinWaitClose, ahk_id %IbmlID%
	Gui, IBML:Destroy
	return IbmlEntry

	IbmlSubmit:
		Gui, IBML:Submit
	return
}

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 27 Jul 2023, 20:58

Can you please make it FileAppend to a text file with a OK and Cancel button.

The submitted text should be entered in a text file with current=.

Thank you for your help!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 27 Jul 2023, 23:24

So you weren’t really just stuck on the multi-line InputBox question? You just wanted someone to write your script? You can take it from here.

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 28 Jul 2023, 01:19

I have InputBox setup that writes to a text file.

I am not sure how to use multiline input write to a text file.

Thank you!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 28 Jul 2023, 03:44

OK. Here’s how you do that. I also added the Cancel button:

Code: Select all

Address := InputBoxML("Enter your address:", "Address", 3)
if (Address != "")
	FileAppend, % Address, MyFile.txt
return

InputBoxML(prompt="", title="", rows=2, width=200) {
	static IbmlEntry
	Gui, IBML:+ToolWindow +hwndIbmlID
	Gui, IBML:Add, Text,, % prompt
	Gui, IBML:Add, Edit, % "vIbmlEntry xm r" rows " w" width
	Gui, IBML:Add, Button, % "gIbmlOK xm+" width/2-65 " w50", OK
	Gui, IBML:Add, Button, gIbmlCancel x+30 w50, Cancel
	Gui, IBML:Show,, % title
	
	WinWaitClose, ahk_id %IbmlID%
	Gui, IBML:Destroy
	return OK ? IbmlEntry : ""

	IbmlOK:
		OK := 1
		Gui, IBML:Submit
	return

	IbmlCancel:
		OK := 0
		Gui, IBML:Cancel
	return

}

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 28 Jul 2023, 12:03

Thank you very much for your help!!

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 28 Jul 2023, 13:11

Can you please tell me how to write to a text file under C:\Program Files\Folder\File.txt

Due to permissions it's not writing to a file under C:\Program Files folder.

Thank you!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 28 Jul 2023, 15:04

I would just not write to a file in that folder. Why does it have to be there? It's very likely that it doesn't.

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 28 Jul 2023, 16:06

I am using an application that only allows to store .txt files in that folder.

Thank you!

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 30 Jul 2023, 19:40

Hi,

How can I use Esc key to close the GUI window.

Thank you!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 30 Jul 2023, 20:07

Code: Select all

Esc::Gui, Cancel

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 01 Aug 2023, 15:15

Can you please tell me where to add this, thank you!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 01 Aug 2023, 15:44

You can put it at the very bottom of the script.

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 02 Aug 2023, 11:39

The following is not working:

Code: Select all

Address := InputBoxML("Enter your address:", "Address", 3)
if (Address != "")
	FileAppend, % Address, MyFile.txt
return

InputBoxML(prompt="", title="", rows=2, width=200) {
	static IbmlEntry
	Gui, IBML:+ToolWindow +hwndIbmlID
	Gui, IBML:Add, Text,, % prompt
	Gui, IBML:Add, Edit, % "vIbmlEntry xm r" rows " w" width
	Gui, IBML:Add, Button, % "gIbmlOK xm+" width/2-65 " w50", OK
	Gui, IBML:Add, Button, gIbmlCancel x+30 w50, Cancel
	Gui, IBML:Show,, % title
	
	WinWaitClose, ahk_id %IbmlID%
	Gui, IBML:Destroy
	return OK ? IbmlEntry : ""

	IbmlOK:
		OK := 1
		Gui, IBML:Submit
	return

	IbmlCancel:
		OK := 0
		Gui, IBML:Cancel
	return

Esc::Gui, Cancel

}

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 02 Aug 2023, 12:48

I said to put that line at the very bottom, not inside a function. Also, it will need the GUI label:

Code: Select all

Esc::Gui, IBML:Cancel

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 02 Aug 2023, 15:27

Now Esc is not working for regular InputBox.

It works without Esc::Gui, IBML:Cancel being added.

Thank you!

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Multiline input

Post by boiler » 02 Aug 2023, 20:14

lionpack wrote: Now Esc is not working for regular InputBox.
I don't understand. What regular InputBox is there in your code?

lionpack
Posts: 14
Joined: 27 Jul 2023, 14:45

Re: Multiline input

Post by lionpack » 03 Aug 2023, 00:27


Post Reply

Return to “Ask for Help (v1)”