如何在AutoHotkey中提示用户输入?

时间:2017-08-01 21:03:52

标签: user-input autohotkey

我正在编写一个AutoHotkey脚本,需要以字符串形式检索键入的用户输入。 (用户名,密码,文件名等)

如何使用AutoHotkey检索用户输入?

2 个答案:

答案 0 :(得分:2)

您可以使用AutoHotkey内置的InputBox

InputBox, UserInput, Enter Name, Please enter a username:, , 300, 150
MsgBox, You entered %UserInput% as your username

Input box for a username

以下是InputBox documentation

的摘录
  

InputBox

     

显示一个输入框,要求用户输入字符串。

InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
     

说明

     

该对话框允许用户输入文本,然后按OK或CANCEL。用户可以通过拖动边框来调整对话框窗口的大小。

     

实施例

InputBox, password, Enter Password, (your input will be hidden), hide 
InputBox, UserInput, Phone Number, Please enter a phone number., , 640, 480
if ErrorLevel
    MsgBox, CANCEL was pressed.
else
    MsgBox, You entered "%UserInput%"

来源 Autohotkey documentation for InputBox

答案 1 :(得分:0)

对于用户名和密码,您可以使用Steven Vascellaro提供的内容。但是对于文件名,要求用户输入文件路径是相当残忍的。

最好使用FileSelectFileFileSelectFolder(官方文档链接示例)。

另外,如果你需要问几个项目,而不是按顺序显示单独的输入框,那么制作一个gui要好得多。幸运的是,它在AutoHotkey中并不累赘:

    Gui Add, Text, xm section, login
    Gui Add, Edit, ys x100 W300 vlogin, %defaultLogin%
    Gui Add, Text, xm section, password
    Gui Add, Edit, ys x100 W300 Password vpassword
    Gui Add, Text, xm section, File: 
    Gui Add, Edit, ys x100 W300 vusrSelFile
    Gui Add, Button, ys, Browse
    Gui Add, Button, section Default, OK
    Gui Add, Button, ys gExit, Cancel
    Gui Show
Exit

ButtonOK:
    Gui Submit
    ;Gui Submit, NoHide if you wanna check contrains and let user fix their input
    MsgBox,
        (LTrim
        login: %login%
        password: %password%
        file: %usrSelFile%
        )
ExitApp


ButtonBrowse:
    FileSelectFile fPath
    GuiControl,, usrSelFile, %fPath%
return

GuiClose:
Exit:
    ExitApp

GuiDropFiles: ; you can also let users drop files on the GUI window
Loop Parse, A_GuiEvent, `n
{
    GuiControl,, usrSelFile, %A_LoopField%
    return ; only first dropped file selected, others ignored
}
return ; in case the event been triggered with no files in list
相关问题