Thursday, August 25, 2022

PowerShell 006 - Send Keystrokes

Send Keystrokes

        Example:

                $wshell = New-Object -ComObject wscript.shell;
                $wshell.SendKeys('text')
                $wshell.SendKeys(~)

        This will type out “text” followed by an Enter keystroke


        Breakdown:

                $wshell = New-Object -ComObject wscript.shell;

        Creates a COM Object with a wscript command and assigns it to the variable $wshell


                $wshell.SendKeys([KEYSTROKES])

        The Object runs the SendKeys command for what is between (). Use single quotes for ‘text’ or one of the codes for non-displayed keys.


Common Non-Displayed Keys

Key

Code

BACKSPACE

{BACKSPACE}, {BS}, or {BKSP}

ENTER

{ENTER} or ~

ESC

{ESC}

DEL or DELETE

{DELETE} or {DEL}

PRINT SCREEN

{PRTSC} (reserved for future use)

TAB

{TAB}


You can combo these with SHIFT, CTRL, and/or ALT by starting with the keys

Key

Code

SHIFT

+

CTRL

^

ALT

%