Function Reference


ControlSend

Sends a string of characters to a control.

ControlSend ( "title", "text", controlID, "string" [, flag = 0] )

Parameters

title The title/hWnd/class of the window to access. See Title special definition.
text The text of the window to access. See Text special definition.
controlID The control to interact with. See Controls.
string String of characters to send to the control.
flag [optional] Changes how "keys" is processed:
    $SEND_DEFAULT (0) = Text contains special characters like + and ! to indicate SHIFT and ALT key-presses (default).
    $SEND_RAW (1) = keys are sent raw.

Constants are defined in "AutoItConstants.au3".

Return Value

Success: 1.
Failure: 0 if window/control is not found.

Remarks

ControlSend() works in a similar way to Send() but it can send key strokes directly to a window/control, rather than just to the active window.

ControlSend() is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages). For normal windows ControlSend() should be way more reliable than a normal Send() - and yes it does send shift, ctrl, alt etc.

As mention in the Send() help the keyboard that send different chars when in CAPS LOCK and using the Shift Key cannot be simulated. An example is the Czech Keyboard. A good workaround is to use the ControlSetText().

The control might first need to be given focus with the ControlFocus() command, specially when referencing an controlID created by the script itself.

Opt("SendKeyDelay",...) alters the length of the brief pause in between sent keystrokes.
Opt("SendKeyDownDelay",...) alters the length of time a key is held down before being released during a keystroke.

Related

ControlCommand, ControlFocus, ControlSetText, Send, SendKeyDelay (Option), SendKeyDownDelay (Option)

Example

Example()

Func Example()
        ; Run Notepad
        Run("notepad.exe")

        ; Wait 10 seconds for the Notepad window to appear.
        Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

        ; Wait for 2 seconds.
        Sleep(2000)

        ; Send a string of text to the edit control of Notepad. The handle returned by WinWait is used for the "title" parameter of ControlSend.
        ControlSend($hWnd, "", "Edit1", "This is some text")

        ; Wait for 2 seconds.
        Sleep(2000)

        ; Close the Notepad window using the handle returned by WinWait.
        WinClose($hWnd)

        ; Now a screen will pop up and ask to save the changes, the classname of the window is called
        ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
        WinWaitActive("[CLASS:#32770]")
        Sleep(500)
        Send("{TAB}{ENTER}")
EndFunc   ;==>Example