diff --git a/builder/vmware/common/step_type_boot_command.go b/builder/vmware/common/step_type_boot_command.go index 05c66de16..35e30c624 100644 --- a/builder/vmware/common/step_type_boot_command.go +++ b/builder/vmware/common/step_type_boot_command.go @@ -6,6 +6,7 @@ import ( "log" "net" "os" + "regexp" "runtime" "strings" "time" @@ -184,6 +185,8 @@ func vncSendString(c *vnc.ClientConn, original string) { special[""] = 0xFFEA special[""] = 0xFFE4 special[""] = 0xFFE2 + special[""] = 0xFFEB + special[""] = 0xFFEC shiftedChars := "~!@#$%^&*()_+{}|:\"<>?" @@ -194,6 +197,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 @@ -232,6 +238,36 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %d", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(keyInterval) + + 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(""):] @@ -265,6 +301,36 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %d", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(keyInterval) + + 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(""):] @@ -298,6 +364,17 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %d", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(keyInterval) + + continue + } + if strings.HasPrefix(original, "") { keyCode = special[""] original = original[len(""):] @@ -331,6 +408,17 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %d", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(keyInterval) + + continue + } + if strings.HasPrefix(original, "") { log.Printf("Special code '' found, sleeping one second") time.Sleep(1 * time.Second)