2018-02-17 21:13:56 -05:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vmware/govmomi/vim25/methods"
|
2018-10-31 17:42:24 -04:00
|
|
|
"github.com/vmware/govmomi/vim25/types"
|
2018-02-17 21:13:56 -05:00
|
|
|
"golang.org/x/mobile/event/key"
|
|
|
|
)
|
|
|
|
|
|
|
|
type KeyInput struct {
|
|
|
|
Scancode key.Code
|
|
|
|
Alt bool
|
|
|
|
Ctrl bool
|
|
|
|
Shift bool
|
|
|
|
}
|
|
|
|
|
2020-06-12 06:42:00 -04:00
|
|
|
func (vm *VirtualMachine) TypeOnKeyboard(input KeyInput) (int32, error) {
|
|
|
|
var spec types.UsbScanCodeSpec
|
|
|
|
|
|
|
|
spec.KeyEvents = append(spec.KeyEvents, types.UsbScanCodeSpecKeyEvent{
|
|
|
|
UsbHidCode: int32(input.Scancode)<<16 | 7,
|
|
|
|
Modifiers: &types.UsbScanCodeSpecModifierType{
|
|
|
|
LeftControl: &input.Ctrl,
|
|
|
|
LeftAlt: &input.Alt,
|
|
|
|
LeftShift: &input.Shift,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-02-17 21:13:56 -05:00
|
|
|
req := &types.PutUsbScanCodes{
|
|
|
|
This: vm.vm.Reference(),
|
|
|
|
Spec: spec,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := methods.PutUsbScanCodes(vm.driver.ctx, vm.driver.client.RoundTripper, req)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Returnval, nil
|
|
|
|
}
|