Partager via


Typing special characters on a virtual machine

On Monday I showed you how to send a string into a virtual machine.  But what if you need to send in special characters?  Well - there is a method for that:

$VMName = "Windows 10 Enterprise"
$VMCS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$($VMName)'"
$keyboard = $VMCS.GetRelated("Msvm_Keyboard")
$keyboard.TypeKey(0x70) | out-null
sleep -Milliseconds 100
$keyboard.TypeKey(0x09) | out-null
sleep -Milliseconds 100
$keyboard.TypeKey(0x32) | out-null
sleep -Milliseconds 1200

This chunk of PowerShell code uses "TypeKey" to send through keycodes (which are all defined here: https://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx).  The code above sends the "F1" key, then the "tab" key and finally a number "2".

Just like TypeText - TypeKey only works when virtual machines are in basic mode; not enhanced mode.

Cheers,
Ben