Send / SendRaw / SendInput / SendPlay / SendEvent: Send Keys & Clicks

Sends simulated keystrokes and mouse clicks to the active window.

Send Keys
SendRaw Keys
SendInput Keys
SendPlay Keys
SendEvent Keys

Parameters

Keys

The sequence of keys to send.

Raw mode - SendRaw or {Raw}: The characters ^+!#{} are interpreted literally rather than translating {Enter} to an ENTER keystroke, ^c to Control-C, etc. To use raw mode with SendInput, SendPlay, or SendEvent, write {Raw} as the first item in the string; for example: SendInput "{Raw}abc".

Raw mode does not affect the interpretation of escape sequences and expressions. For example, SendRaw "``100`%" sends the string `100%. When using ControlSend, it is also necessary to escape literal commas (`,).

Normal mode: When not in raw mode, the following symbols have special meaning: !+^#{}

The modifiers !+^# affect only the very next key. To send the corresponding modifier key on its own, enclose the key name in braces. To just press (hold down) or release the key, follow the key name with the word "down" or "up" as shown below.

Symbol Key Press Release Examples
! {Alt} {Alt down} {Alt up} Send "!a" presses ALT+a
+ {Shift} {Shift down} {Shift up} Send "+abC" sends the text "AbC"
Send "!+a" presses ALT+SHIFT+a
^ {Ctrl} {Ctrl down} {Ctrl up} Send "^{Home}" presses CONTROL+HOME
# {LWin}
{RWin}
{LWin down}
{RWin down}
{LWin up}
{RWin up}
Send "#e" holds down the Windows key and then presses the letter "e"
Symbol Meaning
{ } Braces are used to enclose key names and other options, and to send special characters literally. For example, {Tab} is the Tab key and {!} is a literal exclamation mark.

Note: As capital letters are produced by sending the SHIFT key, A produces a different effect in some programs than a. For example, !A presses ALT+SHIFT+A and !a presses ALT+a. If in doubt, use lowercase.


SendInput and SendPlay: SendInput and SendPlay use the same syntax as SendEvent but are generally faster and more reliable. In addition, they buffer any physical keyboard or mouse activity during the send, which prevents the user's keystrokes from being interspersed with those being sent. By default, Send is synonymous SendPlay; but it can be made a synonym for SendEvent or SendPlay via SendMode. For more details about each mode, see SendInput and SendPlay below.

SendEvent: SendEvent sends keystrokes using the Windows keybd_event function (search MSDN for details). The rate at which keystrokes are sent is determined by SetKeyDelay. SendMode can be used to make Send synonymous with SendEvent or SendPlay.

Key Names: The following table lists the special keys that can be sent (each key name must be enclosed in braces):

   
{F1} - {F24} Function keys. For example: {F12} is the F12 key.
{!} !
{#} #
{+} +
{^} ^
{{} {
{}} }
{Enter} ENTER key on the main keyboard
{Escape} or {Esc} ESCAPE
{Space} SPACE (this is only needed for spaces that appear either at the beginning or the end of the string to be sent -- ones in the middle can be literal spaces)
{Tab} TAB
{Backspace} or {BS} Backspace
{Delete} or {Del} Delete
{Insert} or {Ins} Insert
{Up} Up-arrow key on main keyboard
{Down} Down-arrow down key on main keyboard
{Left} Left-arrow key on main keyboard
{Right} Right-arrow key on main keyboard
{Home} Home key on main keyboard
{End} End key on main keyboard
{PgUp} Page-up key on main keyboard
{PgDn} Page-down key on main keyboard
   
{CapsLock} CapsLock (using SetCapsLockState is more reliable on Win 2k/XP). Sending {CapsLock} might require SetStoreCapslockMode "Off" beforehand.
{ScrollLock} ScrollLock (see also: SetScrollLockState)
{NumLock} NumLock (see also: SetNumLockState)
   
{Control} or {Ctrl} CONTROL (technical info: sends the neutral virtual key but the left scan code)
{LControl} or {LCtrl} Left CONTROL key (technical info: sends the left virtual key rather than the neutral one)
{RControl} or {RCtrl} Right CONTROL key
{Control Down} or {Ctrl Down} Holds the CONTROL key down until {Ctrl Up} is sent. To hold down the left or right key instead, use {RCtrl Down} and {RCtrl Up}.
   
{Alt} ALT (technical info: sends the neutral virtual key but the left scan code)
{LAlt} Left ALT key (technical info: sends the left virtual key rather than the neutral one)
{RAlt} Right ALT key (or AltGr, depending on keyboard layout)
{Alt Down} Holds the ALT key down until {Alt Up} is sent. To hold down the left or right key instead, use {RAlt Down} and {RAlt Up}.
   
{Shift} SHIFT (technical info: sends the neutral virtual key but the left scan code)
{LShift} Left SHIFT key (technical info: sends the left virtual key rather than the neutral one)
{RShift} Right SHIFT key
{Shift Down} Holds the SHIFT key down until {Shift Up} is sent. To hold down the left or right key instead, use {RShift Down} and {RShift Up}.
   
{LWin} Left Windows key
{RWin} Right Windows key
{LWin Down} Holds the left Windows key down until {LWin Up} is sent
{RWin Down} Holds the right Windows key down until {RWin Up} is sent
   
{AppsKey} Windows App key (invokes the right-click or context menu)
{Sleep} Computer SLEEP key.
{ASC nnnnn}

Sends an ALT+nnnnn keypad combination, which can be used to generate special characters that don't exist on the keyboard. To generate ASCII characters, specify a number between 1 and 255. To generate ANSI characters (standard in most languages), specify a number between 128 and 255, but precede it with a leading zero, e.g. {Asc 0133}.

Unicode characters may be generated by specifying a number between 256 and 65535 (without a leading zero). However, this is not supported by all applications. For alternatives, see the section below.

{U+nnnn}

Sends a Unicode character where nnnn is the hexadecimal value of the character excluding the 0x prefix. This typically isn't needed, because Send and ControlSend automatically support Unicode text.

If the character doesn't map to a virtual keycode, SendInput() or WM_CHAR is used to send the character and the current Send mode has no effect.

{vkXX}
{scYYY}
{vkXXscYYY}

Sends a keystroke that has virtual key XX and scan code YYY. For example: Send "{vkFFsc159}". If the sc or vk portion is omitted, the most appropriate value is sent in its place.

The values for XX and YYY are hexadecimal and can usually be determined from the main window's View->Key history menu item. See also: Special Keys

   
{Numpad0} - {Numpad9} Numpad digit keys (as seen when Numlock is ON). For example: {Numpad5} is the digit 5.
{NumpadDot} Numpad Period (as seen when Numlock is ON).
{NumpadEnter} Enter key on keypad
{NumpadMult} Numpad Multiply
{NumpadDiv} Numpad Divide
{NumpadAdd} Numpad Add
{NumpadSub} Numpad Subtract
   
{NumpadDel} Delete key on keypad (this key and the following Numpad keys are used when Numlock is OFF)
{NumpadIns} Insert key on keypad
{NumpadClear} Clear key on keypad (usually the '5' key when Numlock is OFF).
{NumpadUp} Up-arrow key on keypad
{NumpadDown} Down-arrow key on keypad
{NumpadLeft} Left-arrow key on keypad
{NumpadRight} Right-arrow key on keypad
{NumpadHome} Home key on keypad
{NumpadEnd} End key on keypad
{NumpadPgUp} Page-up key on keypad
{NumpadPgDn} Page-down key on keypad
   
{Browser_Back} Select the browser "back" button
{Browser_Forward} Select the browser "forward" button
{Browser_Refresh} Select the browser "refresh" button
{Browser_Stop} Select the browser "stop" button
{Browser_Search} Select the browser "search" button
{Browser_Favorites} Select the browser "favorites" button
{Browser_Home} Launch the browser and go to the home page
{Volume_Mute} Mute/unmute the master volume. Usually equivalent to SoundSet "+1", , "mute".
{Volume_Down} Reduce the master volume. Usually equivalent to SoundSet "-5".
{Volume_Up} Increase the master volume. Usually equivalent to SoundSet "+5".
{Media_Next} Select next track in media player
{Media_Prev} Select previous track in media player
{Media_Stop} Stop media player
{Media_Play_Pause} Play/pause media player
{Launch_Mail} Launch the email application
{Launch_Media} Launch media player
{Launch_App1} Launch user app1
{Launch_App2} Launch user app2
   
{PrintScreen} Print Screen
{CtrlBreak} Ctrl+break
{Pause} Pause
   
{Click [Options]} Sends a mouse click using the same options available in the Click function. For example, {Click} would click the left mouse button once at the mouse cursor's current position, and {Click 100, 200} would click at coordinates 100, 200 (based on CoordMode). To move the mouse without clicking, specify 0 after the coordinates; for example: {Click 100, 200, 0}. The delay between mouse clicks is determined by SetMouseDelay (not SetKeyDelay).
{WheelDown}, {WheelUp}, {WheelLeft}, {WheelRight}, {LButton}, {RButton}, {MButton}, {XButton1}, {XButton2} Sends a mouse button event at the cursor's current position (to have control over position and other options, use {Click} above). The delay between mouse clicks is determined by SetMouseDelay. WheelLeft/Right have no effect on operating systems older than Windows Vista.
{Blind}

When {Blind} is the first item in the string, the program avoids releasing Alt/Control/Shift/Win if they started out in the down position. For example, the hotkey +s::Send {Blind}abc would send ABC rather than abc because the user is holding down the Shift key.

{Blind} also causes SetStoreCapslockMode to be ignored; that is, the state of Capslock is not changed. Finally, {Blind} omits the extra Control keystrokes that would otherwise be sent; such keystrokes prevent: 1) Start Menu appearance during LWin/RWin keystrokes; 2) menu bar activation during Alt keystrokes.

Blind-mode is used internally when remapping a key. For example, the remapping a::b would produce: 1) "b" when you type "a"; 2) uppercase B when you type uppercase A; and 3) Control-B when you type Control-A.

{Blind} is not supported by SendRaw and ControlSendRaw. Furthermore, it is not completely supported by SendPlay, especially when dealing with the modifier keys (Control, Alt, Shift, and Win).

{Raw} Enables Raw mode, which causes the following characters to be interpreted literally: ^+!#{}. Although the string {Raw} need not occur at the beginning of the string, once specified, it stays in effect for the remainder of the string.

Repeating or Holding Down a Key

To repeat a keystroke: Enclose in braces the name of the key followed by the number of times to repeat it. For example:

Send "{DEL 4}"  ; Presses the Delete key 4 times.
Send "{S 30}"   ; Sends 30 uppercase S characters.
Send "+{TAB 4}"  ; Presses Shift-Tab 4 times.

To hold down or release a key: Enclose in braces the name of the key followed by the word Down or Up. For example:

Send "{b down}{b up}"
Send "{TAB down}{TAB up}"
Send "{Up down}"  ; Press down the up-arrow key.
Sleep 1000  ; Keep it down for one second.
Send "{Up up}"  ; Release the up-arrow key.

When a key is held down via the method above, it does not begin auto-repeating like it would if you were physically holding it down (this is because auto-repeat is a driver/hardware feature). However, a Loop can be used to simulate auto-repeat. The following example sends 20 tab keystrokes:

Loop 20
{
    Send "{Tab down}"  ; Auto-repeat consists of consecutive down-events (with no up-events).
    Sleep 30  ; The number of milliseconds between keystrokes (or use SetKeyDelay).
}
Send "{Tab up}"  ; Release the key.

The word DownTemp may also be used. Its effect is the same as Down except for the modifer keys (Control/Shift/Alt/Win). In those cases, DownTemp tells subsequent sends that the key is not permanently down, and may be released whenever a keystroke calls for it. For example, Send "{Control DownTemp}" followed later by Send "a" would produce a normal "a" keystroke, not a control-A keystroke.

General Remarks

There are no specific limitations on which characters the Send function supports. If a character does not exist in the current keyboard layout, it is simulated by sending a Unicode character packet or Alt+nnnnn combination, depending on the version of AutoHotkey. Unicode characters are supported directly as text in Unicode versions of AutoHotkey, or using {U+nnnn} notation in any version.

BlockInput Compared to SendInput/SendPlay: Although the BlockInput function can be used to prevent any keystrokes physically typed by the user from disrupting the flow of simulated keystrokes, it is often better to use SendInput or SendPlay so that keystrokes and mouse clicks become uninterruptible. This is because unlike BlockInput, SendInput/Play does not discard what the user types during the send; instead, such keystrokes are buffered and sent afterward.

When sending a large number of keystrokes, a continuation section can be used to improve readability and maintainability.

Since the operating system does not allow simulation of the CTRL-ALT-DELETE combination, doing something like Send "^!{Delete}" will have no effect.

Send may have no effect on Windows Vista or later if the active window is running with administrative privileges and the script is not. This is due to a security mechanism called User Interface Privilege Isolation.

SendInput

SendInput is generally the preferred method to send keystrokes and mouse clicks because of its superior speed and reliability. Under most conditions, SendInput is nearly instantaneous, even when sending long strings. Since SendInput is so fast, it is also more reliable because there is less opportunity for some other window to pop up unexpectedly and intercept the keystrokes. Reliability is further improved by the fact that anything the user types during a SendInput is postponed until afterward.

Unlike the other sending modes, the operating system limits SendInput to about 5000 characters (this may vary depending on the operating system's version and performance settings). Characters and events beyond this limit are not sent.

Note: SendInput ignores SetKeyDelay because the operating system does not support a delay in this mode. However, when SendInput reverts to SendEvent under the conditions described below, it uses SetKeyDelay -1, 0 (unless SendEvent's KeyDelay is -1,-1, in which case -1,-1 is used). When SendInput reverts to SendPlay, it uses SendPlay's KeyDelay.

If a script other than the one executing SendInput has a low-level keyboard hook installed, SendInput automatically reverts to SendEvent (or SendPlay if SendMode "InputThenPlay" is in effect). This is done because the presence of an external hook disables all of SendInput's advantages, making it inferior to both SendPlay and SendEvent. However, since SendInput is unable to detect a low-level hook in programs other than AutoHotkey v1.0.43+, it will not revert in these cases, making it less reliable than SendPlay/Event.

When SendInput sends mouse clicks by means such as {Click}, and CoordMode "Mouse", "Relative" is in effect (the default), every click will be relative to the window that was active at the start of the send. Therefore, if SendInput intentionally activates another window (by means such as alt-tab), the coordinates of subsequent clicks within the same function will be wrong because they will still be relative to the old window rather than the new one.

SendPlay

Warning: SendPlay may have no effect at all if UAC is enabled, even if the script is running as an administrator. For more information, refer to the FAQ.

SendPlay's biggest advantage is its ability to "play back" keystrokes and mouse clicks in a broader variety of games than the other modes. For example, a particular game may accept hotstrings only when they have the SendPlay option.

Of the three sending modes, SendPlay is the most unusual because it does not simulate keystrokes and mouse clicks per se. Instead, it creates a series of events (messages) that flow directly to the active window (similar to ControlSend, but at a lower level). Consequently, SendPlay does not trigger hotkeys or hotstrings.

Like SendInput, SendPlay's keystrokes do not get interspersed with keystrokes typed by the user. Thus, if the user happens to type something during a SendPlay, those keystrokes are postponed until afterward.

Although SendPlay is considerably slower than SendInput, it is usually faster than the traditional SendEvent mode (even when KeyDelay is -1).

The Windows keys (LWin and RWin) are automatically blocked during a SendPlay if the keyboard hook is installed. This prevents the Start Menu from appearing if the user accidentally presses a Windows key during the send. By contrast, keys other than LWin and RWin do not need to be blocked because the operating system automatically postpones them until after the SendPlay (via buffering).

SendPlay does not use the standard settings of SetKeyDelay and SetMouseDelay. Instead, it defaults to no delay at all, which can be changed as shown in the following examples:

SetKeyDelay 0, 10, "Play"  ; Note that both 0 and -1 are the same in SendPlay mode.
SetMouseDelay 10, "Play"

SendPlay is unable to turn on or off the Capslock, Numlock, or Scroll-lock keys. Similarly, it is unable to change a key's state as seen by GetKeyState unless the keystrokes are sent to one of the script's own windows. Even then, any changes to the left/right modifier keys (e.g. RControl) can be detected only via their neutral counterparts (e.g. Control). Also, SendPlay has other limitations described on the SendMode page.

Unlike SendInput and SendEvent, the user may interrupt a SendPlay by pressing Control-Alt-Del or Control-Escape. When this happens, the remaining keystrokes are not sent but the script continues executing as though the SendPlay had completed normally.

Although SendPlay can send LWin and RWin events, they are sent directly to the active window rather than performing their native operating system function. To work around this, use SendEvent. For example, SendEvent "#r" would show the Start Menu's Run dialog.

Related

SendMode, SetKeyDelay, SetStoreCapslockMode, Escape sequences (e.g. `n), ControlSend, BlockInput, Hotstrings, WinActivate

Examples

Send "Sincerely,{enter}John Smith"  ; Types a two-line signature.
Send "!fs" ; Select the File->Save menu (Alt+F followed by S).
Send "{End}+{Left 4}" ; Jump to the end of the text then send four shift+left-arrow keystrokes.
SendInput "{Raw}A long series of raw characters sent via the fastest method (SendInput)."