Merge pull request #5681 from mcandre/super-key

add super key (vmware builder)
This commit is contained in:
SwampDragons 2018-02-02 13:33:11 -08:00 committed by GitHub
commit 8ae8f31a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 88 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"log"
"net"
"os"
"regexp"
"runtime"
"strings"
"time"
@ -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 := "~!@#$%^&*()_+{}|:\"<>?"
@ -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
@ -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>"):]
@ -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>"):]
@ -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>"):]
@ -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)