Search code examples
autoit

How do I take keyboard input in AutoIt?


I want to write a script in AutoIt, which can take automatic input from the keyboard, let's say A-Z, without user intervention.

Is this possible?


Solution

  • It is unlikely that your program needs to capture all input from all keys. If you do in fact need that kind of user input AutoIt might not be for you - see the post from the author of AutoIt about keyloggers. If you need to take keyboard input of the hotkey type: doing that in AutoIt is super easy.

    HotKeySet("^+{q}", "reactionFunction")
    
    While 1
        ; A loop
    WEnd
    
    Func reactionFunction()
        MsgBox(0, "You pressed CTRL+Shift+q", "You pressed CTRL+Shift+q")
        Exit
    EndFunc
    

    If you want to take user input from an input box that is really easy also.

    $data = InputBox("Enter Something", "Enter some data in the field below.")
    MsgBox(0, "The String You Entered...", "The string you entered is... " & $data)
    

    More information about HotKeySet and InputBox can be found in the AutoIt.chm help file (it's actually a great reference).