mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-27 03:51:20 -05:00
remove duplicated press
This commit is contained in:
parent
585a86fe03
commit
ba767d1663
3 changed files with 6 additions and 42 deletions
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
"github.com/vmware/govmomi/vim25/types"
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
"golang.org/x/mobile/event/key"
|
"golang.org/x/mobile/event/key"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -91,11 +92,11 @@ func (s *StepBootCommand) Run(ctx context.Context, state multistep.StateBag) mul
|
||||||
case key.CodeLeftControl:
|
case key.CodeLeftControl:
|
||||||
// <leftCtrlOn>
|
// <leftCtrlOn>
|
||||||
keyCtrl = downs[i]
|
keyCtrl = downs[i]
|
||||||
case key.CodeLeftShift:
|
default:
|
||||||
// <leftShiftOn>
|
|
||||||
keyShift = downs[i]
|
keyShift = downs[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Sending code %s, shift %v", code, downs[i])
|
||||||
spec.KeyEvents = append(spec.KeyEvents, types.UsbScanCodeSpecKeyEvent{
|
spec.KeyEvents = append(spec.KeyEvents, types.UsbScanCodeSpecKeyEvent{
|
||||||
UsbHidCode: int32(code)<<16 | 7,
|
UsbHidCode: int32(code)<<16 | 7,
|
||||||
Modifiers: &types.UsbScanCodeSpecModifierType{
|
Modifiers: &types.UsbScanCodeSpecModifierType{
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ func TestStepBootCommand_Run(t *testing.T) {
|
||||||
Config: &BootConfig{
|
Config: &BootConfig{
|
||||||
BootConfig: bootcommand.BootConfig{
|
BootConfig: bootcommand.BootConfig{
|
||||||
BootCommand: []string{
|
BootCommand: []string{
|
||||||
" initrd=/install/initrd.gz",
|
|
||||||
"<leftShiftOn><enter><wait><f6><wait><esc><wait>",
|
"<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>",
|
||||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||||
|
|
|
||||||
|
|
@ -103,19 +103,7 @@ func NewUSBDriver(send SendUsbScanCodes, interval time.Duration) *usbDriver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (d *usbDriver) keyEvent(k key.Code, down bool) error {
|
// Flush sends codes to the vm
|
||||||
// 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
|
|
||||||
func (d *usbDriver) Flush() error {
|
func (d *usbDriver) Flush() error {
|
||||||
defer func() {
|
defer func() {
|
||||||
d.codeBuffer = nil
|
d.codeBuffer = nil
|
||||||
|
|
@ -132,28 +120,7 @@ func (d *usbDriver) SendKey(k rune, action KeyAction) error {
|
||||||
keyShift := unicode.IsUpper(k) || strings.ContainsRune(shiftedChars, k)
|
keyShift := unicode.IsUpper(k) || strings.ContainsRune(shiftedChars, k)
|
||||||
keyCode := d.scancodeMap[k]
|
keyCode := d.scancodeMap[k]
|
||||||
log.Printf("Sending char '%c', code %s, shift %v", k, keyCode, keyShift)
|
log.Printf("Sending char '%c', code %s, shift %v", k, keyCode, keyShift)
|
||||||
|
d.send(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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d.err
|
return d.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,10 +134,7 @@ func (d *usbDriver) SendSpecial(special string, action KeyAction) error {
|
||||||
switch action {
|
switch action {
|
||||||
case KeyOn:
|
case KeyOn:
|
||||||
d.send(keyCode, true)
|
d.send(keyCode, true)
|
||||||
case KeyOff:
|
case KeyOff, KeyPress:
|
||||||
d.send(keyCode, false)
|
|
||||||
case KeyPress:
|
|
||||||
d.send(keyCode, true)
|
|
||||||
d.send(keyCode, false)
|
d.send(keyCode, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue