Module to facilitate sending keystrokes to a VMware virtual machine. Note that this module depends on PowerCLI being available.
This module uses similar formatting for control characters and special characters to the AutoIt Send function.
A string of just plain characters will be split up into a sequence of USB Keyboard HID Events and sent to the Virtual Machine.
The characters "!", "+", "^", and "#" have special meanings. By prefixing any of these characters you will modify the next key in the sequence.
Character | Modifier |
---|---|
! | ALT |
+ | SHIFT |
^ | CTRL |
# | META (Windows/Apple Key) |
Some examples:
Example | Sends Keys |
---|---|
^c | Ctrl + C |
^!{DELETE} | Ctrl + Alt + Delete |
!{F4} | Alt + F4 |
There are a number of keys on your keyboard that don't have a direct ASCII representation, to send those keys we use a HID map file. You can view that file, and see a list of available special keys here. Special characters should be enclosed in curly braces (i.e. DELETE should be {DELETE} in your string).
If you need to type any of the control characters or a literal curly brace you can wrap the character in curly braces. For example {+} is "+", {{} is "{", etc...
Sending a string of keypresses
$VM | Send-VMKeystrokes 'hello world'
Sending Ctrl+Alt+Del
$VM | Send-VMKeystrokes '^!{DELETE}'
You can also chain together sends, for example to login you might...
$VM |
Send-VMKeystrokes '^!{DELETE}' -PauseAfterMilliseconds 500 -PassThru |
Send-VMKeystrokes $UserName -Verbatim -PassThru |
Send-VMKeystrokes '{TAB}' -PassThru |
Send-VMKeystrokes $PlainTextPassword -Verbatim -SendCarriageReturn
Significant inspiration for this module came from code created by William Lam and David Rodriguez. The primary code source I pulled from is VMKeystrokes.ps1. Significant changes in both how this module handles input as well as how it's processed has been made.