sendevent

sends mouse or keyboard events 

Command


SYNOPSIS

sendevent event [event]...


DESCRIPTION

The sendevent utility sends mouse or keyboard events. These events are the equivalent of moving or clicking the mouse or typing keys on the keyboard.

Each type of event has its own format:

Mouse Events

sendevent supports the following mouse button events:

{l} 

means left mouse button down.

{L} 

means left mouse button up.

{m} 

means middle mouse button down.

{M} 

means middle mouse button up.

{r} 

means right mouse button down.

{R} 

means right mouse button up.

You can include multiple mouse button events in one set of {}. For example, you could use {lL} rather than {l}{L} or {rR} rather than {r}{R}.

sendevent supports the following mouse movement events:

{ax, y} 
{Ax, y} 

moves the mouse pointer to position (x, y) on the screen.

{x1, y1} 

moves the mouse pointer from its current position (x, y) on the screen to position (x+x1, y+y1).

Finally, on 8.1/2012R2/10/2016/2019/11/2022 systems, sendevent supports the following wheelmouse events:

{wn} 

moves the mouse pointer n pixels, where n can be positive or negative, depending on which way the wheel was to be rolled. The system default is 120 pixels equals one wheelmouse click.

{x1} 

means X button 1 down.

{X1} 

means X button 1 up.

{x2} 

means X button 2 down.

{X2} 

means X button 2 up.

Keyboard Events

sendevent supports the keyboard events:

VK_ACCEPT               VK_ADD                  VK_APPS
VK_ATTN                 VK_BACK                 VK_BROWSER_BACK
VK_BROWSER_FAVORITES    VK_BROWSER_FORWARD      VK_BROWSER_HOME
VK_BROWSER_REFRESH      VK_BROWSER_SEARCH       VK_BROWSER_STOP
VK_CANCEL               VK_CAPITAL              VK_CLEAR
VK_CONTROL              VK_CONVERT              VK_CRSEL
VK_DECIMAL              VK_DELETE               VK_DIVIDE
VK_DOWN                 VK_END                  VK_EREOF
VK_ESCAPE               VK_EXECUTE              VK_EXSEL
VK_F1                   VK_F2                   VK_F3
VK_F4                   VK_F5                   VK_F6
VK_F7                   VK_F8                   VK_F9
VK_F10                  VK_F11                  VK_F12
VK_F13                  VK_F14                  VK_F15
VK_F16                  VK_F17                  VK_F18
VK_F19                  VK_F20                  VK_F21
VK_F22                  VK_F23                  VK_F24
VK_FINAL                VK_HANGUL               VK_HANJA
VK_HELP                 VK_HOME                 VK_ICO_00
VK_ICO_CLEAR            VK_ICO_HELP             VK_INSERT
VK_JUNJA                VK_KANA                 VK_KANJI
VK_LAUNCH_APP1          VK_LAUNCH_APP2          VK_LAUNCH_MAIL
VK_LAUNCH_MEDIA_SELECT  VK_LBUTTON              VK_LCONTROL
VK_LEFT                 VK_LMENU                VK_LSHIFT
VK_LWIN                 VK_MBUTTON              VK_MEDIA_NEXT_TRACK
VK_MEDIA_PLAY_PAUSE     VK_MEDIA_PREV_TRACK     VK_MEDIA_STOP
VK_MENU                 VK_MODECHANGE           VK_MULTIPLY
VK_NEXT                 VK_NONAME               VK_NONCONVERT
VK_NUMLOCK              VK_NUMPAD0              VK_NUMPAD1
VK_NUMPAD2              VK_NUMPAD3              VK_NUMPAD4
VK_NUMPAD5              VK_NUMPAD6              VK_NUMPAD7
VK_NUMPAD8              VK_NUMPAD9              VK_OEM_1
VK_OEM_102              VK_OEM_2                VK_OEM_3
VK_OEM_4                VK_OEM_5                VK_OEM_6
VK_OEM_7                VK_OEM_8                VK_OEM_ATTN
VK_OEM_AUTO             VK_OEM_AX               VK_OEM_BACKTAB
VK_OEM_CLEAR            VK_OEM_COMMA            VK_OEM_COPY
VK_OEM_CUSEL            VK_OEM_ENLW             VK_OEM_FINISH
VK_OEM_FJ_JISHO         VK_OEM_FJ_LOYA          VK_OEM_FJ_MASSHOU
VK_OEM_FJ_ROYA          VK_OEM_FJ_TOUROKU       VK_OEM_JUMP
VK_OEM_MINUS            VK_OEM_NEC_EQUAL        VK_OEM_PA1
VK_OEM_PA2              VK_OEM_PA3              VK_OEM_PERIOD
VK_OEM_PLUS             VK_OEM_RESET            VK_OEM_WSCTRL
VK_PA1                  VK_PACKET               VK_PAUSE
VK_PLAY                 VK_PRINT                VK_PRIOR
VK_PROCESSKEY           VK_RBUTTON              VK_RCONTROL
VK_RETURN               VK_RIGHT                VK_RMENU
VK_RSHIFT               VK_RWIN                 VK_SCROLL
VK_SELECT               VK_SEPARATOR            VK_SHIFT
VK_SLEEP                VK_SNAPSHOT             VK_SPACE
VK_SUBTRACT             VK_TAB                  VK_UP
VK_VOLUME_DOWN          VK_VOLUME_MUTE          VK_VOLUME_UP
VK_XBUTTON1             VK_XBUTTON2             VK_ZOOM
VK_0                    VK_1                    VK_2
VK_3                    VK_4                    VK_5
VK_6                    VK_7                    VK_8
VK_9                    VK_A                    VK_B
VK_C                    VK_D                    VK_E
VK_F                    VK_G                    VK_H
VK_I                    VK_J                    VK_K
VK_L                    VK_M                    VK_N
VK_O                    VK_P                    VK_Q
VK_R                    VK_S                    VK_T
VK_U                    VK_V                    VK_W
VK_X                    VK_Y                    VK_Z

In addition, supports the following mappings so that more common key names can be used:

Keyboard Event            Mapping
VK_BACK                 VK_BACKSPACE
VK_CAPITAL              VK_CAPSLOCK
VK_CONTROL              VK_CTRL
VK_LCONTROL             VK_LCTRL
VK_RCONTROL             VK_RCTRL
VK_DELETE               VK_DEL
VK_ESCAPE               VK_ESC
VK_INSERT               VK_INS
VK_MENU                 VK_ALT
VK_LMENU                VK_LALT
VK_RMENU                VK_RALT
VK_NEXT                 VK_PAGEDOWN
VK_NEXT                 VK_PGDN
VK_OEM_1                VK_SEMICOLON
VK_OEM_2                VK_SLASH
VK_OEM_3                VK_TICK
VK_OEM_3                VK_BACKQUOTE
VK_OEM_4                VK_OPENBRACKET
VK_OEM_5                VK_BACKSLASH
VK_OEM_6                VK_CLOSEBRACKET
VK_OEM_7                VK_QUOTE
VK_OEM_COMMA            VK_COMMA
VK_OEM_MINUS            VK_MINUS
VK_OEM_PERIOD           VK_PERIOD
VK_OEM_PLUS             VK_PLUS
VK_PRIOR                VK_PAGEUP
VK_PRIOR                VK_PGUP
VK_RETURN               VK_ENTER
VK_SCROLL               VK_SCROLL_LOCK
VK_SNAPSHOT             VK_PRINTSCREEN
VK_START                VK_LWIN

Descriptions of these keyboard events can be found at: http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/userinput/VirtualKeyCodes.asp

You can omit the leading VK_. If the first character of the name of the keyboard event is uppercase then this is a key-up event. Otherwise it is a key-down event. Here are a few examples:

<vk_a><VK_A>  is the equivalent of typing a
<a><A>  is the equivalent of typing a
<shift><vk_a><VK_A><SHIFT> is the equivalent of typing A
<shift><a><A><SHIFT> is the equivalent of typing A
<return><RETURN> is the equivalent of typing RETURN or ENTER

Note:

Be sure to always enter the matching key-up event for any key-down event. Not doing so can leave the keyboard in a funny state. For example <shift> without <SHIFT> leaves the keyboard in SHIFT state. To fix this, just type the left SHIFT key or send <SHIFT> with sendevent.

To simplify sending strings using sendevent, built-in mappings are provided for most keyboard characters, allowing you to just type the characters that you want to send. For example:

a is the equivalent of <a><A>
A is the equivalent of <shift><a><A><SHIFT>
` is the equivalent of <vk_oem_3><VK_OEM_3>
~ is the equivalent of <shift><vk_oem_3><VK_OEM_3><SHIFT>
and so on

The command characters (, <, {, and the escape character \ take precedence over the built-in mappings. If you wish to send one of these characters using its built-in mapping, just preface it with \. For example:

sendevent "this is an \(example\) of using \\-escaping"

Note:

The mappings for some keys are only valid in the OEM code page, as is evidenced by the explicit reference to OEM in the name of the keyboard event.


EXAMPLES

Send a command to a KornShell window that has the keyboard focus:

sendevent "echo abcde<return><RETURN>"

Do the above action twice in a row:

sendevent ":2:(echo abcde<return><RETURN>)"

Send a string to coordinates (100,200) (the left mouse button is also clicked to ensure the focus is on that location):

sendevent "{a100,200}{lL}this is a string"

DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

>0 

An error occurred.


PORTABILITY

Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


AVAILABILITY

PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
winctrl


PTC MKS Toolkit 10.4 Documentation Build 39.