From d069dc5b7c18e39ac332ab12566cdf801b14bd32 Mon Sep 17 00:00:00 2001 From: Andrew Pennebaker Date: Sat, 9 Dec 2017 12:02:20 -0600 Subject: [PATCH] handle holding a-z keys, such as for boot options (vmware builder) --- .../vmware/common/step_type_boot_command.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/builder/vmware/common/step_type_boot_command.go b/builder/vmware/common/step_type_boot_command.go index b100b609e..520ed4320 100644 --- a/builder/vmware/common/step_type_boot_command.go +++ b/builder/vmware/common/step_type_boot_command.go @@ -5,6 +5,7 @@ import ( "log" "net" "os" + "regexp" "runtime" "strings" "time" @@ -195,6 +196,9 @@ func vncSendString(c *vnc.ClientConn, original string) { keyInterval = delay } + azOnRegex := regexp.MustCompile("^<(?P[a-zA-Z])On>") + azOffRegex := regexp.MustCompile("^<(?P[a-zA-Z])Off>") + // TODO(mitchellh): Ripe for optimizations of some point, perhaps. for len(original) > 0 { var keyCode uint32 @@ -244,6 +248,25 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if azOnRegex.MatchString(original) { + m := azOnRegex.FindStringSubmatch(original) + r, _ := utf8.DecodeRuneInString(m[1]) + original = original[len(""):] + keyCode = uint32(r) + keyShift = unicode.IsUpper(r) || strings.ContainsRune(shiftedChars, r) + + log.Printf("Special code '%s' found, replacing with %d, shift %v", m[0], keyCode, keyShift) + + if keyShift { + c.KeyEvent(KeyLeftShift, true) + } + + c.KeyEvent(keyCode, true) + time.Sleep(keyInterval) + + continue + } + if strings.HasPrefix(original, "") { keyCode = special[""] original = original[len(""):] @@ -288,6 +311,25 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if azOffRegex.MatchString(original) { + m := azOffRegex.FindStringSubmatch(original) + r, _ := utf8.DecodeRuneInString(m[1]) + original = original[len(""):] + keyCode = uint32(r) + keyShift = unicode.IsUpper(r) || strings.ContainsRune(shiftedChars, r) + + log.Printf("Special code '%s' found, replacing with %d, shift %v", m[0], keyCode, keyShift) + + if keyShift { + c.KeyEvent(KeyLeftShift, false) + } + + c.KeyEvent(keyCode, false) + time.Sleep(keyInterval) + + continue + } + if strings.HasPrefix(original, "") { keyCode = special[""] original = original[len(""):]