Skip to content

Commit

Permalink
Merge pull request #5681 from mcandre/super-key
Browse files Browse the repository at this point in the history
add super key (vmware builder)
  • Loading branch information
SwampDragons authored Feb 2, 2018
2 parents 997f8e4 + d069dc5 commit 8ae8f31
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions builder/vmware/common/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net"
"os"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -184,6 +185,8 @@ func vncSendString(c *vnc.ClientConn, original string) {
special["<rightAlt>"] = 0xFFEA
special["<rightCtrl>"] = 0xFFE4
special["<rightShift>"] = 0xFFE2
special["<leftSuper>"] = 0xFFEB
special["<rightSuper>"] = 0xFFEC

shiftedChars := "~!@#$%^&*()_+{}|:\"<>?"

Expand All @@ -194,6 +197,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 @@ -232,6 +238,36 @@ func vncSendString(c *vnc.ClientConn, original string) {
continue
}

if strings.HasPrefix(original, "<leftSuperOn>") {
keyCode = special["<leftSuper>"]
original = original[len("<leftSuperOn>"):]
log.Printf("Special code '<leftSuperOn>' 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("<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 @@ -265,6 +301,36 @@ func vncSendString(c *vnc.ClientConn, original string) {
continue
}

if strings.HasPrefix(original, "<leftSuperOff>") {
keyCode = special["<leftSuper>"]
original = original[len("<leftSuperOff>"):]
log.Printf("Special code '<leftSuperOff>' 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("<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 Expand Up @@ -298,6 +364,17 @@ func vncSendString(c *vnc.ClientConn, original string) {
continue
}

if strings.HasPrefix(original, "<rightSuperOn>") {
keyCode = special["<rightSuper>"]
original = original[len("<rightSuperOn>"):]
log.Printf("Special code '<rightSuperOn>' found, replacing with: %d", keyCode)

c.KeyEvent(keyCode, true)
time.Sleep(keyInterval)

continue
}

if strings.HasPrefix(original, "<rightAltOff>") {
keyCode = special["<rightAlt>"]
original = original[len("<rightAltOff>"):]
Expand Down Expand Up @@ -331,6 +408,17 @@ func vncSendString(c *vnc.ClientConn, original string) {
continue
}

if strings.HasPrefix(original, "<rightSuperOff>") {
keyCode = special["<rightSuper>"]
original = original[len("<rightSuperOff>"):]
log.Printf("Special code '<rightSuperOff>' found, replacing with: %d", keyCode)

c.KeyEvent(keyCode, false)
time.Sleep(keyInterval)

continue
}

if strings.HasPrefix(original, "<wait>") {
log.Printf("Special code '<wait>' found, sleeping one second")
time.Sleep(1 * time.Second)
Expand Down

0 comments on commit 8ae8f31

Please sign in to comment.