2017-08-31 81 views
3

我有一個AutoHotkey腳本,需要從用戶讀取多行員工數據。如何在AutoHotkey中讀取多行用戶輸入?

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

不幸的是,一個InputBox只允許用戶輸入文本的單行。嘗試添加換行符輸入將改爲提交輸入的任何數據。

如何在AutoHotkey腳本中輸入多行用戶輸入?

user input

回答

2

這實現了一個通用的多輸入功能

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 
} 
+0

綁定變量需要是靜態的或全局的 –

+0

MultiLineInput()返回用戶的輸入作爲字符串,即使已選擇取消。 –

+0

你有興趣把它作爲一個圖書館在GitHub上嗎?我發現自己經常使用這個功能,並且很想幫助進一步開發它。 –

2

這說明一個多輸入框

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 

enter image description here