How can I read multiple lines of user input in AutoHotkey?

寵の児 提交于 2019-12-22 10:27:26

问题


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



来源:https://stackoverflow.com/questions/45986293/how-can-i-read-multiple-lines-of-user-input-in-autohotkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!