Add key press interval to virtualbox.
This commit is contained in:
parent
59376294ef
commit
81d127768c
|
@ -64,7 +64,7 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag)
|
||||||
|
|
||||||
return driver.VBoxManage(args...)
|
return driver.VBoxManage(args...)
|
||||||
}
|
}
|
||||||
d := bootcommand.NewPCATDriver(sendCodes, 20)
|
d := bootcommand.NewPCATDriver(sendCodes, 25)
|
||||||
|
|
||||||
ui.Say("Typing the boot command...")
|
ui.Say("Typing the boot command...")
|
||||||
for i, command := range s.BootCommand {
|
for i, command := range s.BootCommand {
|
||||||
|
|
|
@ -3,15 +3,20 @@ package bootcommand
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendCodeFunc will be called to send codes to the VM
|
// SendCodeFunc will be called to send codes to the VM
|
||||||
type SendCodeFunc func([]string) error
|
type SendCodeFunc func([]string) error
|
||||||
|
|
||||||
type pcATDriver struct {
|
type pcATDriver struct {
|
||||||
|
interval time.Duration
|
||||||
sendImpl SendCodeFunc
|
sendImpl SendCodeFunc
|
||||||
specialMap map[string][]string
|
specialMap map[string][]string
|
||||||
scancodeMap map[rune]byte
|
scancodeMap map[rune]byte
|
||||||
|
@ -21,6 +26,12 @@ type pcATDriver struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPCATDriver(send SendCodeFunc, chunkSize int) *pcATDriver {
|
func NewPCATDriver(send SendCodeFunc, chunkSize int) *pcATDriver {
|
||||||
|
// We delay (default 100ms) between each input event to allow for CPU or
|
||||||
|
// network latency. See PackerKeyEnv for tuning.
|
||||||
|
keyInterval := common.PackerKeyDefault
|
||||||
|
if delay, err := time.ParseDuration(os.Getenv(common.PackerKeyEnv)); err == nil {
|
||||||
|
keyInterval = delay
|
||||||
|
}
|
||||||
// Scancodes reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
// Scancodes reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
||||||
//
|
//
|
||||||
// Scancodes are recorded here in pairs. The first entry represents
|
// Scancodes are recorded here in pairs. The first entry represents
|
||||||
|
@ -87,6 +98,7 @@ func NewPCATDriver(send SendCodeFunc, chunkSize int) *pcATDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &pcATDriver{
|
return &pcATDriver{
|
||||||
|
interval: keyInterval,
|
||||||
sendImpl: send,
|
sendImpl: send,
|
||||||
specialMap: sMap,
|
specialMap: sMap,
|
||||||
scancodeMap: scancodeMap,
|
scancodeMap: scancodeMap,
|
||||||
|
@ -107,6 +119,7 @@ func (d *pcATDriver) Finalize() error {
|
||||||
if err := d.sendImpl(b); err != nil {
|
if err := d.sendImpl(b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
time.Sleep(d.interval)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue