How can I read multiple lines of user input in Aut

2019-05-16 22:34发布

问题:

I have an AutoHotkey script which needs to read multiple lines of employee data from a user.

InputBox, userInput, Employee Records, Please enter employee records. (One per line)

Unfortunately, an InputBox only allows users to enter a single line of text. Trying to add newlines with Enter will instead submit whatever data has been entered.

How can I take in multiple lines of user input in an AutoHotkey script?

回答1:

This implements a generic multiline input function

F3::MsgBox % MultiLineInput( "Employee Records", "Please enter employee records (One per line):" )

MultiLineInput(title, prompt)
{
  static input
  input := ""
  Gui, Add, Text,, %prompt%
  Gui, Add, Edit, w400 h60 vinput
  Gui, Add, Button, gokay_pressed, Okay
  Gui, Add, Button, cancel X+8 YP+0, Cancel
  Gui, Show, Center autosize, %title%
  WinWaitClose %title%
  return input

  okay_pressed:
    Gui Submit
    Gui Destroy
    return

  GuiClose:
  GuiEscape:
  ButtonCancel:
    Gui, Destroy
    return
}


回答2:

This demonstrates a multi-line input box

F2::
  Gui, Add, Text,, Please enter employee records (One per line):
  Gui, Add, Edit, w600 h60 vinput
  Gui, Add, Button, gokay_pressed, Okay
  Gui, Add, Button, cancel X+8 YP+0, Cancel
  Gui, Show, Center autosize, Employee Records
  Return

okay_pressed:
  Gui Submit
  Gui Destroy
  MsgBox %input%
  Return

GuiClose:
GuiEscape:
ButtonCancel:
  Gui, Destroy
  return