ControlSend / ControlSendText

Sends simulated keystrokes or text to a window or control.

ControlSend Keys , Control, WinTitle, WinText, ExcludeTitle, ExcludeText
ControlSendText: Same parameters as above.



Type: String

The sequence of keys to send (see the Send function for details). The rate at which characters are sent is determined by SetKeyDelay.

Unlike the Send function, mouse clicks cannot be sent by ControlSend. Use ControlClick for that.


Type: String, Integer or Object

The control's ClassNN, text or HWND, or an object with a Hwnd property. For details, see The Control Parameter.

If this parameter is omitted, the keystrokes will be sent directly to the target window instead of one of its controls (see Automating Winamp for an example).


Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.


Type: String

If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.


Type: String

Windows whose titles include this value will not be considered.


Type: String

Windows whose text include this value will not be considered.

Error Handling

A TargetError is thrown if the window or control could not be found.


ControlSendText sends the individual characters of the Keys parameter without translating {Enter} to Enter, ^c to Ctrl+C, etc. For details, see Text mode. It is also valid to use {Raw} or {Text} with ControlSend.

If the Control parameter is omitted, this function will attempt to send directly to the target window by sending to its topmost control (which is often the correct one) or the window itself if there are no controls. This is useful if a window does not appear to have any controls at all, or just for the convenience of not having to worry about which control to send to.

By default, modifier keystrokes (Ctrl, Alt, Shift, and Win) are sent as they normally would be by the Send function. This allows command prompt and other console windows to properly detect uppercase letters, control characters, etc. It may also improve reliability in other ways.

However, in some cases these modifier events may interfere with the active window, especially if the user is actively typing during a ControlSend or if Alt is being sent (since Alt activates the active window's menu bar). This can be avoided by explicitly sending modifier up and down events as in this example:

ControlSend "{Alt down}f{Alt up}", "Edit1", "Untitled - Notepad"

The method above also allows the sending of modifier keystrokes (Ctrl, Alt, Shift, and Win) while the workstation is locked (protected by logon prompt).

BlockInput should be avoided when using ControlSend against a console window such as command prompt. This is because it might prevent capitalization and modifier keys such as Ctrl from working properly.

The value of SetKeyDelay determines the speed at which keys are sent. If the target window does not receive the keystrokes reliably, try increasing the press duration via the second parameter of SetKeyDelay as in these examples:

SetKeyDelay 10, 10
SetKeyDelay 0, 10
SetKeyDelay -1, 0

If the target control is an Edit control (or something similar), the following are usually more reliable and faster than ControlSend:

EditPaste("This text will be inserted at the caret position.", ControlName, WinTitle)
ControlSetText("This text will entirely replace any current text.", ControlName, WinTitle)

ControlSend is generally not capable of manipulating a window's menu bar. To work around this, use MenuSelect. If that is not possible due to the nature of the menu bar, you could try to discover the message that corresponds to the desired menu item by following the SendMessage Tutorial.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

SetKeyDelay, Escape sequences (e.g. `n) , Control functions, Send, Automating Winamp


Opens Notepad minimized and send it some text.

Run "Notepad",, "Min", &PID  ; Run Notepad minimized.
WinWait "ahk_pid " PID  ; Wait for it to appear.
; Send the text to the inactive Notepad edit control.
; The third parameter is omitted so the last found window is used.
ControlSend "This is a line of text in the notepad window.{Enter}", "Edit1"
ControlSendText "Notice that {Enter} is not sent as an Enter keystroke with ControlSendText.", "Edit1"

Msgbox "Press OK to activate the window to see the result."
WinActivate "ahk_pid " PID  ; Show the result.

Opens the command prompt and sent it some text.

SetTitleMatchMode 2
Run A_ComSpec,,, &PID  ; Run command prompt.
WinWait "ahk_pid " PID  ; Wait for it to appear.
ControlSend "ipconfig{Enter}",, "cmd.exe"  ; Send directly to the command prompt window.