This cmdlet is part of the Vexasoft Cmdlet Library. You can download it now or click here to find out more.

Send-KeyboardInput

Synopsis

Send keyboard input to a specific desktop window.

Syntax

  • Send-KeyboardInput [-Keys] [-Window]

Description

Send-KeyboardInput is used to send input to Windows applications as if the data had been typed on the keyboard.

Send-KeyboardInput requires that you use the Get-Window cmdlet to identify the target application window. The keyboard input is written to the default cursor location of the target application window. Cursor positioning keys and shortcuts such as Tab, Ctrl-Tab, the Window key, ALT-F etc. can also be sent as part of the keyboard input. Special keys are passed in the following way:

BACKSPACE = {BACKSPACE}
BREAK = {BREAK}
CAPS LOCK = {CAPSLOCK}
DELETE = {DEL}
DOWN ARROW = {DOWN}
END = {END}
ENTER = {ENTER}
ESC = {ESC}
HELP = {HELP}
HOME = {HOME}
INSERT = {INSERT}
LEFT ARROW = {LEFT}
NUM LOCK = {NUMLOCK}
PAGE DOWN = {PGDN}
PAGE UP = {PGUP}
PRINT SCREEN = {PRTSC}
RIGHT ARROW = {RIGHT}
SCROLL LOCK = {SCROLLLOCK}
TAB = {TAB}
UP ARROW = {UP}
CTRL = +
ALT = ^
SHIFT = %
+ = {+}
^ = {^}
% = {%}
~ = {~}
F1 = {F1}
F2 = {F2}
F3 = {F3}
F4 = {F4}
F5 = {F5}
F6 = {F6}
F7 = {F7}
F8 = {F8}
F9 = {F9}
F10 = {F10}
F11 = {F11}
F12 = {F12}

When using SHIFT, CTRL or ALT (+, ^ or %) in conjunction with another key, place the modifying symbol immediately before the affected character. For example, ALT-F is represented as %F. Note that to actually write a +, ^ or % character you must enclose the character in curled braces. For example, 100% is represented as 100{%}.

Also note that when passing any string in PowerShell that contains a { or } you must enclose the entire string in quotes.

Parameters

  • Keys The keys to type.
  • Window The target application window. AppWindow objects are generated by the Get-Window cmdlet.

Inputs

Send-KeyboardInput must be used in conjunction with the Get-Window cmdlet and accepts the output of Get-Window as an input object.

Outputs

Send-KeyboardInput does not output any PowerShell objects.

Notes

There are no notes associated with the Send-KeyboardInput cmdlet.

Example 1

Send-KeyboardInput must be used in conjunction with the Get-Window cmdlet.

This command sends keyboard input to a window titled "Manual Registration Window". The keystrokes are being sent to automate a manual process that otherwise could not normally be automated. The {tab} and {enter} functions are used to navigate around the window.

C:\PS>Get-Window -Title "Manual Registration Process" | Send-KeyboardInput "auser{tab}acompany{enter}"

Example 2

This command will send the keystrokes 100 + 50 and an Enter to the calculator application, causing it to perform the calculation.

Note the the + symbol is surrounded by curly braces. When sending keys '+' is used to signify the CTRL key modifier. In this case we want it to be treated literally. Without the curly braces around the +, the cmdlet would send 100 CTRL+5 0 and an Enter.

C:\PS>Get-Window -Title calculator | Send-KeyboardInput "100{+}50{enter}"