remove duplicated press

This commit is contained in:
Moss 2020-06-12 11:00:21 +02:00
parent 585a86fe03
commit ba767d1663
3 changed files with 6 additions and 42 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/packer/template/interpolate"
"github.com/vmware/govmomi/vim25/types"
"golang.org/x/mobile/event/key"
"log"
"time"
)
@ -91,11 +92,11 @@ func (s *StepBootCommand) Run(ctx context.Context, state multistep.StateBag) mul
case key.CodeLeftControl:
// <leftCtrlOn>
keyCtrl = downs[i]
case key.CodeLeftShift:
// <leftShiftOn>
default:
keyShift = downs[i]
}
log.Printf("Sending code %s, shift %v", code, downs[i])
spec.KeyEvents = append(spec.KeyEvents, types.UsbScanCodeSpecKeyEvent{
UsbHidCode: int32(code)<<16 | 7,
Modifiers: &types.UsbScanCodeSpecModifierType{

View File

@ -26,7 +26,6 @@ func TestStepBootCommand_Run(t *testing.T) {
Config: &BootConfig{
BootConfig: bootcommand.BootConfig{
BootCommand: []string{
" initrd=/install/initrd.gz",
"<leftShiftOn><enter><wait><f6><wait><esc><wait>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",

View File

@ -103,19 +103,7 @@ func NewUSBDriver(send SendUsbScanCodes, interval time.Duration) *usbDriver {
}
}
//func (d *usbDriver) keyEvent(k key.Code, down bool) error {
// if d.err != nil {
// return nil
// }
// if err := d.sendImpl(k, down); err != nil {
// d.err = err
// return err
// }
// //time.Sleep(d.interval)
// return nil
//}
// Flush does nothing here
// Flush sends codes to the vm
func (d *usbDriver) Flush() error {
defer func() {
d.codeBuffer = nil
@ -132,28 +120,7 @@ func (d *usbDriver) SendKey(k rune, action KeyAction) error {
keyShift := unicode.IsUpper(k) || strings.ContainsRune(shiftedChars, k)
keyCode := d.scancodeMap[k]
log.Printf("Sending char '%c', code %s, shift %v", k, keyCode, keyShift)
switch action {
case KeyOn:
if keyShift {
d.send(key.CodeLeftShift, true)
}
d.send(keyCode, true)
case KeyOff:
if keyShift {
d.send(key.CodeLeftShift, false)
}
d.send(keyCode, false)
case KeyPress:
if keyShift {
d.send(key.CodeLeftShift, true)
}
d.send(keyCode, true)
d.send(keyCode, false)
if keyShift {
d.send(key.CodeLeftShift, false)
}
}
d.send(keyCode, keyShift)
return d.err
}
@ -167,10 +134,7 @@ func (d *usbDriver) SendSpecial(special string, action KeyAction) error {
switch action {
case KeyOn:
d.send(keyCode, true)
case KeyOff:
d.send(keyCode, false)
case KeyPress:
d.send(keyCode, true)
case KeyOff, KeyPress:
d.send(keyCode, false)
}