Virtualization Framework with programmatic keyboard / pointing device.

I'm curious if there is a way to add a programmatically controlled keyboard and pointing device to a virtual machine created using Virtualization.framework (for the purposes of sandboxed automation). All of the types I've found in that framework have very little in the way of configurability and seem to be uniquely intended for use with a VZVirtualMachineView.

On the other hand, Hypervisor.framework seems extremely low-level so I'm wondering if there is something in between the two I can use to achieve this.

Answered by DTS Engineer in 816832022
[is there] a way to add a programmatically controlled keyboard and pointing device to a virtual machine created using Virtualization framework

Not directly.

As you’ve noted, you can add a virtual keyboard to your virtual machine but there’s no way to inject events into that keyboard. VZVirtualMachineView will do that for you, so you could possibly inject events into it and have it forward the events to the virtual machine. However, that’s somewhat convoluted.

Having said that, it’s not impossible. See this thread.

Regardless of what else you do here, I encourage you to file an enhancement request against the Virtualization framework for the features you’d like to see it support. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer
[is there] a way to add a programmatically controlled keyboard and pointing device to a virtual machine created using Virtualization framework

Not directly.

As you’ve noted, you can add a virtual keyboard to your virtual machine but there’s no way to inject events into that keyboard. VZVirtualMachineView will do that for you, so you could possibly inject events into it and have it forward the events to the virtual machine. However, that’s somewhat convoluted.

Having said that, it’s not impossible. See this thread.

Regardless of what else you do here, I encourage you to file an enhancement request against the Virtualization framework for the features you’d like to see it support. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Virtualization Framework with programmatic keyboard / pointing device.
 
 
Q