Skip to content

Commit

Permalink
handle holding a-z keys, such as for boot options (vmware builder)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Pennebaker committed Dec 10, 2017
1 parent 4acc98a commit d069dc5
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions builder/vmware/common/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net"
"os"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -195,6 +196,9 @@ func vncSendString(c *vnc.ClientConn, original string) {
keyInterval = delay
}

azOnRegex := regexp.MustCompile("^<(?P<ordinary>[a-zA-Z])On>")
azOffRegex := regexp.MustCompile("^<(?P<ordinary>[a-zA-Z])Off>")

// TODO(mitchellh): Ripe for optimizations of some point, perhaps.
for len(original) > 0 {
var keyCode uint32
Expand Down Expand Up @@ -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("<aOn>"):]
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, "<leftAltOff>") {
keyCode = special["<leftAlt>"]
original = original[len("<leftAltOff>"):]
Expand Down Expand Up @@ -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("<aOff>"):]
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, "<rightAltOn>") {
keyCode = special["<rightAlt>"]
original = original[len("<rightAltOn>"):]
Expand Down

0 comments on commit d069dc5

Please sign in to comment.