Search code examples
autoit

How do I enter a value in a text box using AutoIt?


I have two text boxes and one button. How do I enter a value into a text box and press Enter to the button using AutoIt?


Solution

  • It's that easy for an example:

    $gui = GUICreate("Test GUI", 640, 280)
    $input = GUICtrlCreateInput("Input field", 10, 10, 620, 20)
    $edit = GUICtrlCreateEdit("Edit Control with Text", 10, 40, 620, 200)
    $button = GUICtrlCreateButton("Button", 10, 250, 620, 20)
    
    GUISetState(@SW_SHOW)
    
    Sleep(2000)
    
    ControlSetText("Test GUI", "", $input, "New text for the input")
    ControlSetText("Test GUI", "", $edit, "New text for the edit... with some bla bla bla...")
    Sleep(500)
    ControlClick("Test GUI", "", $button)
    Sleep(500)
    ControlFocus("Test GUI", "", $input)
    
    Sleep(4000)
    
    ControlSetText("Test GUI", "", "[CLASS:Edit; INSTANCE:1]", "New text for the input, referenced as Edit1")
    ControlSetText("Test GUI", "", "[CLASS:Edit; INSTANCE:2]", "New text for the edit..., referenced as Edit2 with some bla bla bla...")
    Sleep(500)
    ControlClick("Test GUI", "", "[CLASS:Button; INSTANCE:1]")
    Sleep(500)
    ControlFocus("Test GUI", "", $input)
    
    Sleep(4000)
    

    And besides, your english is quite unclear, you should put a little more effort in your questions ;-)

    If you want to find out, what "[CLASS:Edit; INSTANCE:1]" you must use, try out the "AutoIt v3 Window Info" tool. And start reading some of the pretty good documentation. Good luck!