Search code examples
user-inputautohotkey

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


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?

user input


Solution

  • 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
    }