Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

To combine a key withPrecede the key code with

SendKeys VBA and VB

https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa202943(v=office.10)?redirectedfrom=MSDN

https://stackoverflow.com/questions/17849522/how-to-perform-keystroke-inside-powershell

https://superuser.com/questions/1249976/sendkeys-method-in-powershell/1250038

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".

To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.


#SENDKEYS_FUNC
function Do-SendKeys {
    param (
        $SENDKEYS,
        $PROCESS
    )
    $wshell = New-Object -ComObject wscript.shell;
    IF ($WINDOWTITLE) {$wshell.AppActivate((Get-Process $PROCESS).ID)}
    Sleep 2
    IF ($SENDKEYS) {$wshell.SendKeys($SENDKEYS)}
    Sleep 2
}
function Do-SendKeysMSPrint {
    param (
        $SENDKEYS,
        $PROCESS
    )
    Do-SendKeys -SENDKEYS '^p%p'
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.SendKeys($SENDKEYS)
    Sleep 2
} 
Do-SendKeys -PROCESS Print -SENDKEYS '{TAB}{TAB}'
Do-SendKeys -PROCESS Print
Do-SendKeys -SENDKEYS '%{f4}'
SHIFT+ (plus sign)
CTRL^ (caret)
ALT% (percent sign)
BACKSPACE{BACKSPACE} or {BS}
BREAK{BREAK}
CAPS LOCK{CAPSLOCK}
CLEAR{CLEAR}
DELETE or DEL{DELETE} or {DEL}
DOWN ARROW{DOWN}
END{END}
ENTER (numeric keypad){ENTER}
ENTER~ (tilde)
ESC{ESCAPE} or {ESC}
HELP{HELP}
HOME{HOME}
INS{INSERT}
LEFT ARROW{LEFT}
NUM LOCK{NUMLOCK}
PAGE DOWN{PGDN}
PAGE UP{PGUP}
RETURN{RETURN}
RIGHT ARROW{RIGHT}
SCROLL LOCK{SCROLLLOCK}
TAB{TAB}
UP ARROW{UP}
F1 through F15{F1} through {F15}
  • No labels