InputBox

From AutoIt Wiki
Jump to navigation Jump to search

InputBox displays a popup box prompting the user to enter a string. Adapted from AutoIt doc.

Syntax

InputBox("title","prompt"[,"default"[,"password char[Option]"[,width[,height[,left,top[,timeout[,hwnd]]]]]])

Parameters

ParamPurpose
titleSets the title of the input box
promptSets the prompt to the user
defaultSets user input field to default text
password charSet the character value to replace input.(Optional)
widthSet the width of the window in pixels. Height must also be set. Default value -1 or "Default".(Optional)
heightSet the height of the window in pixels. Width must also be set. Default value -1 or "Default".(Optional)
leftSet the distance of the window from the left side of the screen in pixels. Top must also be set. Default value -1 or "Default".(Optional)
topSet the distance of the window from the top of the screen in pixels. Left must also be set. Default value -1 or "Default".(Optional)
timeoutSet the number of seconds till close.(Optional)
hwndSet the window handle as the parent.(Optional)

Title, Prompt, & Default

The title, prompt, and default fields set the title of the box, the user prompt, and the initial value of the user input field respectively.

Local $str = InputBox("Login","Enter your name:","John Generic")

Password Character

The password char parameter replaces all inputed characters with the first value. Placing a whitespace in the first character position will cause input to be shown as normal. Subsequent characters are used to restrict and enforce input.

  • Options
    • M = Mandatory entry before continuing
    • n = Only n characters may be entered where n is an integer
; Require input no larger than 5 characters in length, replace input with "*"
Local $str = InputBox("Password Check","Please enter your password:","noobs","*M5")

Width & Height

As mentioned above, width and height must be defined together. The size is determined by pixels with a minimum size of 190x115 and a default size of 250x190 however the box is resizable by the user.

Local $str = InputBox("Size Counts","Resize me!","","",190,115)

Left & Top

Like width and height, left and top must be defined together. The position of the box is measured in pixels from the leftmost position on the screen to the topmost. Thus the upper left hand corner of your screen would be at coordinates (0,0). By default the input box is centered but is also movable by the user.

Local $str = InputBox("Move Me","Move me!","","",-1,-1,0,0) ; top left corner of the screen

Timeout

The timeout parameter acts to close the InputBox after x number of seconds have passed.

Local $str = InputBox("Type Fast","What's 6 x 7?","","",-1,-1,Default,Default,3) ; box will close in 3 seconds

If the InputBox times out before a choice is made a 2 is returned.

Return Values

Success: Returns input string and sets @Error

Failure: Returns empty string and sets @Error

Error CodeReason
0Successful execution
1Cancel button pressed
2Timeout occurred
3InputBox failed to open properly
Local $str = InputBox("Try It","Do Something!","stuff","",10)
MsgBox(0,"Bada Bing",@error & " " & $str)