handle holding a-z keys, such as for boot options (vmware builder)
This commit is contained in:
parent
4acc98a729
commit
d069dc5b7c
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -195,6 +196,9 @@ func vncSendString(c *vnc.ClientConn, original string) {
|
||||||
keyInterval = delay
|
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.
|
// TODO(mitchellh): Ripe for optimizations of some point, perhaps.
|
||||||
for len(original) > 0 {
|
for len(original) > 0 {
|
||||||
var keyCode uint32
|
var keyCode uint32
|
||||||
|
@ -244,6 +248,25 @@ func vncSendString(c *vnc.ClientConn, original string) {
|
||||||
continue
|
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>") {
|
if strings.HasPrefix(original, "<leftAltOff>") {
|
||||||
keyCode = special["<leftAlt>"]
|
keyCode = special["<leftAlt>"]
|
||||||
original = original[len("<leftAltOff>"):]
|
original = original[len("<leftAltOff>"):]
|
||||||
|
@ -288,6 +311,25 @@ func vncSendString(c *vnc.ClientConn, original string) {
|
||||||
continue
|
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>") {
|
if strings.HasPrefix(original, "<rightAltOn>") {
|
||||||
keyCode = special["<rightAlt>"]
|
keyCode = special["<rightAlt>"]
|
||||||
original = original[len("<rightAltOn>"):]
|
original = original[len("<rightAltOn>"):]
|
||||||
|
|
Loading…
Reference in New Issue