Automating the keyboard under Virtual Server

If you want to perform any significant amount of virtual machine automation with Virtual Server – you will need to figure out how to drive the keyboard. There are a number of possible methods for doing this – and each one has its advantages:

VM.keyboard.TypeASCIItext

This method is handy for typing large strings of ASCII text. Its advantages are that it provides an easy method to input large strings of text. It is also handy because one of the problems that you can encounter while automating keyboard input is that it is easy to ‘type too fast’ for the guest operating system to keep up with – and this method makes sure that the text gets typed at just the right speed. An example of using this method would be:

VM.keyboard.TypeASCIItext “Hello World!”

VM.keyboard.TypeKeySequence

While this method is more complicated than ‘TypeASCIItext’ it does provide an easy way to automate complex key combinations. It requires you to specify key down and key up events in the order that you want them to happen. A common usage of this method is to type CTRL+ALT+DEL on a virtual machine – as follows:

VM.keyboard.TypeKeySequence "DOWN,Key_LeftCtrl, DOWN,Key_LeftAlt, DOWN,Key_Delete, UP,Key_LeftCtrl, UP,Key_LeftAlt, UP,Key_Delete"

VM.keyboard.PressAndReleaseKey

This method provides the easiest way to send through a single key down and key up event for a given key. This is most useful for situations where you need to hit Enter or Tab to navigate a user interface. For example:

VM.keyboard.PressAndReleaseKey "Key_Enter"

One final point to make is that the key codes used for Virtual Server can be found in the Virtual Server Programmers guide in the ‘Key Identifiers Reference’ section.

Cheers,
Ben