From 936020e22b6add766dcdf50d618169d1787af35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 18 Jan 2026 17:59:25 +0100 Subject: [PATCH] Add bootcommand mappings for left/right command and option keys Awaiting the merge of the feature in the upstream Packer SDK repo. See hashicorp/packer-plugin-sdk#293 --- .web-docs/components/builder/tart/README.md | 4 +++- builder/tart/step_run.go | 14 ++++++++++++++ builder/tart/vnc.go | 5 +++++ docs/builders/tart.mdx | 4 +++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.web-docs/components/builder/tart/README.md b/.web-docs/components/builder/tart/README.md index 75ef6370..e0db6882 100644 --- a/.web-docs/components/builder/tart/README.md +++ b/.web-docs/components/builder/tart/README.md @@ -272,8 +272,10 @@ For more examples of various boot commands, see the sample projects from our -Additionally, Tart builder supports the following custom commands that utilize computer vision: +Additionally, Tart builder supports the following custom commands: +* ` ` - Simulates pressing the ⌘ key. +* ` ` - Simulates pressing the ⌥ key. * `` — waits for the given string to appear in the VM's screen output * the `string` can be a simple word, a sentence or a regular expression * alternative to `` command with large values diff --git a/builder/tart/step_run.go b/builder/tart/step_run.go index e953d7f6..1b52bc61 100644 --- a/builder/tart/step_run.go +++ b/builder/tart/step_run.go @@ -266,6 +266,20 @@ func typeBootCommandOverVNC( command = stringClickRegex.ReplaceAllString(command, fmt.Sprintf(`%c${1}%c`, ClickStringStart, ClickStringEnd)) + // Waiting for https://github.com/hashicorp/packer-plugin-sdk/pull/293 + leftCommandRegex := regexp.MustCompile(``) + command = leftCommandRegex.ReplaceAllString(command, + fmt.Sprintf(`<%c${1}>`, LeftCommand)) + rightCommandRegex := regexp.MustCompile(``) + command = rightCommandRegex.ReplaceAllString(command, + fmt.Sprintf(`<%c${1}>`, RightCommand)) + leftOptionRegex := regexp.MustCompile(``) + command = leftOptionRegex.ReplaceAllString(command, + fmt.Sprintf(`<%c${1}>`, LeftOption)) + rightOptionRegex := regexp.MustCompile(``) + command = rightOptionRegex.ReplaceAllString(command, + fmt.Sprintf(`<%c${1}>`, RightOption)) + seq, err := bootcommand.GenerateExpressionSequence(command) if err != nil { err := fmt.Errorf("Failed to parse the boot command: %s", err) diff --git a/builder/tart/vnc.go b/builder/tart/vnc.go index 62cd6662..ca460fbf 100644 --- a/builder/tart/vnc.go +++ b/builder/tart/vnc.go @@ -77,6 +77,11 @@ const ( ClickStringStart rune = 0xE0002 ClickStringEnd rune = 0xE0003 + + LeftCommand rune = 0xFFE9 + RightCommand rune = 0xFFEA + LeftOption rune = 0xFFE7 + RightOption rune = 0xFFE8 ) func (d *customDriver) SendKey(key rune, action bootcommand.KeyAction) error { diff --git a/docs/builders/tart.mdx b/docs/builders/tart.mdx index a4009242..2fb23c6b 100644 --- a/docs/builders/tart.mdx +++ b/docs/builders/tart.mdx @@ -90,8 +90,10 @@ For more advanced examples, please refer to the [`example/` directory](https://g @include 'packer-plugin-sdk/bootcommand/BootConfig.mdx' -Additionally, Tart builder supports the following custom commands that utilize computer vision: +Additionally, Tart builder supports the following custom commands: +* ` ` - Simulates pressing the ⌘ key. +* ` ` - Simulates pressing the ⌥ key. * `` — waits for the given string to appear in the VM's screen output * the `string` can be a simple word, a sentence or a regular expression * alternative to `` command with large values