From a87ad05866346d6c610fa49caf5bdb72e6877975 Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Sun, 31 Jul 2016 19:05:10 +0100 Subject: [PATCH] Add support for ctrl, shift and alt keys. Add support for using ctrl, shift and alt as key modifiers. So you can now achieve ctrl+c by using "c". Updated documentation for new key stroke tokens. --- .../common/step_type_boot_command.go | 79 ++++++++ builder/qemu/step_type_boot_command.go | 174 ++++++++++++++++++ .../common/step_type_boot_command.go | 78 ++++++++ .../vmware/common/step_type_boot_command.go | 138 ++++++++++++++ .../docs/builders/parallels-iso.html.md | 20 ++ website/source/docs/builders/qemu.html.md | 20 ++ .../docs/builders/virtualbox-iso.html.md | 20 ++ .../source/docs/builders/vmware-iso.html.md | 20 ++ 8 files changed, 549 insertions(+) diff --git a/builder/parallels/common/step_type_boot_command.go b/builder/parallels/common/step_type_boot_command.go index a1b3d562d..37637fc65 100644 --- a/builder/parallels/common/step_type_boot_command.go +++ b/builder/parallels/common/step_type_boot_command.go @@ -186,6 +186,13 @@ func scancodes(message string) []string { special[""] = []string{"49", "c9"} special[""] = []string{"51", "d1"} + special[""] = []string{"38", "b8"} + special[""] = []string{"1d", "9d"} + special[""] = []string{"2a", "aa"} + special[""] = []string{"e038", "e0b8"} + special[""] = []string{"e01d", "e09d"} + special[""] = []string{"36", "b6"} + shiftedChars := "!@#$%^&*()_+{}:\"~|<>?" scancodeIndex := make(map[string]uint) @@ -214,6 +221,78 @@ func scancodes(message string) []string { for len(message) > 0 { var scancode []string + if strings.HasPrefix(message, "") { + scancode = []string{"38"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 38") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"1d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 1d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"2a"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 2a") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"b8"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: b8") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"9d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 9d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"aa"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: aa") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e038"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e038") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e01d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e01d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"36"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 36") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e0b8"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e0b8") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e09d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e09d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"b6"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: b6") + } + if strings.HasPrefix(message, "") { log.Printf("Special code found, will sleep 1 second at this point.") scancode = []string{"wait"} diff --git a/builder/qemu/step_type_boot_command.go b/builder/qemu/step_type_boot_command.go index f720d6f12..fc999429f 100644 --- a/builder/qemu/step_type_boot_command.go +++ b/builder/qemu/step_type_boot_command.go @@ -136,6 +136,12 @@ func vncSendString(c *vnc.ClientConn, original string) { special[""] = 0xFF57 special[""] = 0xFF55 special[""] = 0xFF56 + special[""] = 0xFFE9 + special[""] = 0xFFE3 + special[""] = 0xFFE1 + special[""] = 0xFFEA + special[""] = 0xFFE4 + special[""] = 0xFFE2 shiftedChars := "~!@#$%^&*()_+{}|:\"<>?" @@ -144,6 +150,174 @@ func vncSendString(c *vnc.ClientConn, original string) { var keyCode uint32 keyShift := false + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + // qemu is picky, so no matter what, wait a small period + time.Sleep(100 * time.Millisecond) + + continue + } + if strings.HasPrefix(original, "") { log.Printf("Special code '' found, sleeping one second") time.Sleep(1 * time.Second) diff --git a/builder/virtualbox/common/step_type_boot_command.go b/builder/virtualbox/common/step_type_boot_command.go index d227cf760..ab9cd5c70 100644 --- a/builder/virtualbox/common/step_type_boot_command.go +++ b/builder/virtualbox/common/step_type_boot_command.go @@ -141,6 +141,12 @@ func scancodes(message string) []string { special[""] = []string{"4f", "cf"} special[""] = []string{"49", "c9"} special[""] = []string{"51", "d1"} + special[""] = []string{"38", "b8"} + special[""] = []string{"1d", "9d"} + special[""] = []string{"2a", "aa"} + special[""] = []string{"e038", "e0b8"} + special[""] = []string{"e01d", "e09d"} + special[""] = []string{"36", "b6"} shiftedChars := "~!@#$%^&*()_+{}|:\"<>?" @@ -170,6 +176,78 @@ func scancodes(message string) []string { for len(message) > 0 { var scancode []string + if strings.HasPrefix(message, "") { + scancode = []string{"38"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 38") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"1d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 1d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"2a"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 2a") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"b8"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: b8") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"9d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 9d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"aa"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: aa") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e038"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e038") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e01d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e01d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"36"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: 36") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e0b8"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e0b8") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"e09d"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: e09d") + } + + if strings.HasPrefix(message, "") { + scancode = []string{"b6"} + message = message[len(""):] + log.Printf("Special code '' found, replacing with: b6") + } + if strings.HasPrefix(message, "") { log.Printf("Special code found, will sleep 1 second at this point.") scancode = []string{"wait"} diff --git a/builder/vmware/common/step_type_boot_command.go b/builder/vmware/common/step_type_boot_command.go index 9750aaa71..b74dff32e 100644 --- a/builder/vmware/common/step_type_boot_command.go +++ b/builder/vmware/common/step_type_boot_command.go @@ -159,6 +159,12 @@ func vncSendString(c *vnc.ClientConn, original string) { special[""] = 0xFF57 special[""] = 0xFF55 special[""] = 0xFF56 + special[""] = 0xFFE9 + special[""] = 0xFFE3 + special[""] = 0xFFE1 + special[""] = 0xFFEA + special[""] = 0xFFE4 + special[""] = 0xFFE2 shiftedChars := "~!@#$%^&*()_+{}|:\"<>?" @@ -167,6 +173,138 @@ func vncSendString(c *vnc.ClientConn, original string) { var keyCode uint32 keyShift := false + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, true) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + continue + } + + if strings.HasPrefix(original, "") { + keyCode = special[""] + original = original[len(""):] + log.Printf("Special code '' found, replacing with: %s", keyCode) + + c.KeyEvent(keyCode, false) + time.Sleep(time.Second / 10) + + continue + } + if strings.HasPrefix(original, "") { log.Printf("Special code '' found, sleeping one second") time.Sleep(1 * time.Second) diff --git a/website/source/docs/builders/parallels-iso.html.md b/website/source/docs/builders/parallels-iso.html.md index 61fef28f9..649c8ebb0 100644 --- a/website/source/docs/builders/parallels-iso.html.md +++ b/website/source/docs/builders/parallels-iso.html.md @@ -256,10 +256,30 @@ proper key: - `` `` - Simulates pressing the page up and page down keys. +- `` `` - Simulates pressing the alt key. + +- `` `` - Simulates pressing the ctrl key. + +- `` `` - Simulates pressing the shift key. + +- `` `` - Simulates pressing and holding the alt key. + +- `` `` - Simulates pressing and holding the ctrl key. + +- `` `` - Simulates pressing and holding the shift key. + +- `` `` - Simulates releasing a held alt key. + +- `` `` - Simulates releasing a held ctrl key. + +- `` `` - Simulates releasing a held shift key. + - `` `` `` - Adds a 1, 5 or 10 second pause before sending any additional keys. This is useful if you have to generally wait for the UI to update before typing more. +When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, otherwise they will be held down until the machine reboots. Use lowercase characters as well inside modifiers. For example: to simulate ctrl+c use `c`. + In addition to the special keys, each command to type is treated as a [configuration template](/docs/templates/configuration-templates.html). The available variables are: diff --git a/website/source/docs/builders/qemu.html.md b/website/source/docs/builders/qemu.html.md index e5aee5ce1..15cb91700 100644 --- a/website/source/docs/builders/qemu.html.md +++ b/website/source/docs/builders/qemu.html.md @@ -354,6 +354,24 @@ by the proper key: - `` `` - Simulates pressing the page up and page down keys. +- `` `` - Simulates pressing the alt key. + +- `` `` - Simulates pressing the ctrl key. + +- `` `` - Simulates pressing the shift key. + +- `` `` - Simulates pressing and holding the alt key. + +- `` `` - Simulates pressing and holding the ctrl key. + +- `` `` - Simulates pressing and holding the shift key. + +- `` `` - Simulates releasing a held alt key. + +- `` `` - Simulates releasing a held ctrl key. + +- `` `` - Simulates releasing a held shift key. + - `` `` `` - Adds a 1, 5 or 10 second pause before sending any additional keys. This is useful if you have to generally wait for the UI to update before typing more. @@ -361,6 +379,8 @@ by the proper key: - ` ` - Add user defined time.Duration pause before sending any additional keys. For example `` or `` +When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, otherwise they will be held down until the machine reboots. Use lowercase characters as well inside modifiers. For example: to simulate ctrl+c use `c`. + In addition to the special keys, each command to type is treated as a [configuration template](/docs/templates/configuration-templates.html). The available variables are: diff --git a/website/source/docs/builders/virtualbox-iso.html.md b/website/source/docs/builders/virtualbox-iso.html.md index 59f7d1e59..48fcbe9f1 100644 --- a/website/source/docs/builders/virtualbox-iso.html.md +++ b/website/source/docs/builders/virtualbox-iso.html.md @@ -290,10 +290,30 @@ by the proper key: - `` `` - Simulates pressing the page up and page down keys. +- `` `` - Simulates pressing the alt key. + +- `` `` - Simulates pressing the ctrl key. + +- `` `` - Simulates pressing the shift key. + +- `` `` - Simulates pressing and holding the alt key. + +- `` `` - Simulates pressing and holding the ctrl key. + +- `` `` - Simulates pressing and holding the shift key. + +- `` `` - Simulates releasing a held alt key. + +- `` `` - Simulates releasing a held ctrl key. + +- `` `` - Simulates releasing a held shift key. + - `` `` `` - Adds a 1, 5 or 10 second pause before sending any additional keys. This is useful if you have to generally wait for the UI to update before typing more. +When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, otherwise they will be held down until the machine reboots. Use lowercase characters as well inside modifiers. For example: to simulate ctrl+c use `c`. + In addition to the special keys, each command to type is treated as a [configuration template](/docs/templates/configuration-templates.html). The available variables are: diff --git a/website/source/docs/builders/vmware-iso.html.md b/website/source/docs/builders/vmware-iso.html.md index 54cdc2615..9599c0630 100644 --- a/website/source/docs/builders/vmware-iso.html.md +++ b/website/source/docs/builders/vmware-iso.html.md @@ -314,10 +314,30 @@ by the proper key: - `` `` - Simulates pressing the page up and page down keys. +- `` `` - Simulates pressing the alt key. + +- `` `` - Simulates pressing the ctrl key. + +- `` `` - Simulates pressing the shift key. + +- `` `` - Simulates pressing and holding the alt key. + +- `` `` - Simulates pressing and holding the ctrl key. + +- `` `` - Simulates pressing and holding the shift key. + +- `` `` - Simulates releasing a held alt key. + +- `` `` - Simulates releasing a held ctrl key. + +- `` `` - Simulates releasing a held shift key. + - `` `` `` - Adds a 1, 5 or 10 second pause before sending any additional keys. This is useful if you have to generally wait for the UI to update before typing more. +When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, otherwise they will be held down until the machine reboots. Use lowercase characters as well inside modifiers. For example: to simulate ctrl+c use `c`. + In addition to the special keys, each command to type is treated as a [configuration template](/docs/templates/configuration-templates.html). The available variables are: