Read key interval from ENV; default to 100ms

This commit is contained in:
Chris Bednarski 2016-05-31 18:40:16 -07:00
parent da083506f1
commit d0c64f90d5
1 changed files with 8 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net"
"os"
"runtime"
"strings"
"time"
@ -360,10 +361,15 @@ func vncSendString(c *vnc.ClientConn, original string) {
// Send the key events. We add a 100ms sleep after each key event
// to deal with network latency and the OS responding to the keystroke.
// It is kind of arbitrary but it is better than nothing.
keyInterval := 100 * time.Millisecond
if envInterval, err := time.ParseDuration(os.Getenv("PACKER_KEY_INTERVAL")); err == nil {
keyInterval = envInterval
}
c.KeyEvent(keyCode, true)
time.Sleep(10 * time.Millisecond)
time.Sleep(keyInterval)
c.KeyEvent(keyCode, false)
time.Sleep(10 * time.Millisecond)
time.Sleep(keyInterval)
if keyShift {
c.KeyEvent(KeyLeftShift, false)