Skip to content

Add bootcommand mappings for left/right command and option keys#293

Open
torarnv wants to merge 2 commits intohashicorp:mainfrom
torarnv:add-command-option-bootcommand-keys
Open

Add bootcommand mappings for left/right command and option keys#293
torarnv wants to merge 2 commits intohashicorp:mainfrom
torarnv:add-command-option-bootcommand-keys

Conversation

@torarnv
Copy link

@torarnv torarnv commented May 29, 2025

When automating macOS systems it's convenient to refer to the keys by their natural names, and for the VNC driver none of the existing special keys mapped to option, so this enables boot commands using the option key.

@torarnv torarnv requested a review from a team as a code owner May 29, 2025 12:57
@torarnv
Copy link
Author

torarnv commented May 29, 2025

I see there's a copy of the docs in cmd/packer-sdc/internal/renderdocs/docs-partials/packer-plugin-sdk/bootcommand/BootConfig.mdx as well. Do I need to update those? If so, how?

@hisaac
Copy link

hisaac commented Sep 18, 2025

@anshulsharma-hashicorp, @anurag5sh, @JenGoldstrich, would one of you have time to review this PR, or suggest someone else who could? I'd love to get this one merged in. It would make working with macOS VMs nicer.

@torarnv
Copy link
Author

torarnv commented Oct 17, 2025

@anshulsharma-hashicorp, @anurag5sh, @JenGoldstrich is there any feedback on this PR? How do we proceed? Thanks 😊

@torarnv
Copy link
Author

torarnv commented Jan 18, 2026

@anshulsharma-hashicorp, @anurag5sh, @JenGoldstrich Can you please comment on this PR? Thanks

The super key maps to ⌘ for the USB driver, but for the VNC
driver ⌘ is produced by left/right Alt, so we can't promise
that leftSuper/rightSuper produces ⌘.
When automating macOS systems it's convenient to refer to the
keys by their natural names, and for the VNC driver none of the
existing special keys mapped to option, so this enables boot
commands using the option key.
@torarnv torarnv force-pushed the add-command-option-bootcommand-keys branch from c4c5259 to 81531cc Compare January 18, 2026 16:47
torarnv added a commit to torarnv/packer-plugin-tart that referenced this pull request Jan 18, 2026
Awaiting the merge of the feature in the upstream Packer SDK repo,
let's override the plugin SDK with a branch that has the feature.

See hashicorp/packer-plugin-sdk#293
torarnv added a commit to torarnv/packer-plugin-tart that referenced this pull request Jan 27, 2026
Awaiting the merge of the feature in the upstream Packer SDK repo.

See hashicorp/packer-plugin-sdk#293
torarnv added a commit to torarnv/packer-plugin-tart that referenced this pull request Jan 27, 2026
Awaiting the merge of the feature in the upstream Packer SDK repo.

See hashicorp/packer-plugin-sdk#293
torarnv added a commit to torarnv/packer-plugin-tart that referenced this pull request Jan 27, 2026
Awaiting the merge of the feature in the upstream Packer SDK repo.

See hashicorp/packer-plugin-sdk#293
@torarnv
Copy link
Author

torarnv commented Jan 27, 2026

@tanmay-hc Is Packer maintained still?

edigaryev pushed a commit to cirruslabs/packer-plugin-tart that referenced this pull request Jan 28, 2026
Awaiting the merge of the feature in the upstream Packer SDK repo.

See hashicorp/packer-plugin-sdk#293
@torarnv
Copy link
Author

torarnv commented Feb 18, 2026

@devashish-patel @taru-garg-hashicorp @kp2099 Would appreciate a review of this PR, thanks!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the boot command special-key vocabulary so macOS automation can refer to Command/Option by their natural names, including left/right variants, across the boot command parser and relevant drivers.

Changes:

  • Added <leftCommand>/<rightCommand> and <leftOption>/<rightOption> to the boot command grammar and regenerated the parser.
  • Added corresponding key mappings for the VNC and USB bootcommand drivers.
  • Updated boot command documentation to mention the new special keys.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
bootcommand/vnc_driver.go Adds VNC keysym mappings for left/right Command and Option.
bootcommand/usb_driver.go Adds USB scancode mappings for left/right Command and Option.
bootcommand/config.go Documents the new special keys.
bootcommand/boot_command.pigeon Extends the grammar to recognize the new special keys.
bootcommand/boot_command.go Regenerated parser output reflecting the grammar changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +85
// Verified against the built-in VNC server on macOS
sMap["leftcommand"] = 0xFFE9
sMap["rightcommand"] = 0xFFEA
sMap["leftoption"] = 0xFFE7
sMap["rightoption"] = 0xFFE8
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New special-key mappings were added here, but there’s no corresponding test coverage to ensure <leftCommand>, <rightCommand>, <leftOption>, and <rightOption> generate the expected keysyms (and remain case-insensitive). Consider extending vnc_driver_test.go to assert the emitted key events for these new tokens.

Copilot uses AI. Check for mistakes.
Comment on lines +77 to 82
// https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf
"leftcommand": key.CodeLeftGUI,
"rightcommand": key.CodeRightGUI,
"leftoption": key.CodeLeftAlt,
"rightoption": key.CodeRightAlt,
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New special-key mappings were added here, but the USB driver tests currently don’t cover <leftCommand>, <rightCommand>, <leftOption>, or <rightOption>. Consider adding cases to usb_driver_test.go to verify these tokens map to the intended key.Code values (and that mixed-case input still works).

Copilot uses AI. Check for mistakes.
Comment on lines +71 to 73
/ "leftCommand"i / "rightCommand"i / "leftOption"i / "rightOption"i
// left/right must go last, to not take priority over {left/right}Foo
/ "left"i / "right"i / "menu"i
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grammar now accepts <leftCommand>, <rightCommand>, <leftOption>, and <rightOption>, but the PC-XT driver (pc_xt_driver.go) does not map these specials. This means templates using these keys will parse successfully but fail at runtime with “special … not found” when the PC-XT driver is used. Consider adding aliases in the PC-XT driver (e.g., command -> left/right super (GUI), option -> left/right alt) or restrict/qualify these tokens to drivers that support them.

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +71
// - `<leftCommand> <rightCommand>` - Simulates pressing the ⌘ key.
//
// - `<leftOption> <rightOption>` - Simulates pressing the ⌥ key.
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc block now lists <leftCommand>/<rightCommand> and <leftOption>/<rightOption> as generally available special keys, but the PC-XT driver does not currently implement these mappings. Either add the aliases to the PC-XT driver or clarify here that these keys are only supported by specific drivers (e.g., VNC/USB) to avoid runtime surprises.

Suggested change
// - `<leftCommand> <rightCommand>` - Simulates pressing the ⌘ key.
//
// - `<leftOption> <rightOption>` - Simulates pressing the ⌥ key.
// - `<leftCommand> <rightCommand>` - Simulates pressing the ⌘ key. Supported
// only by certain keyboard drivers (such as VNC/USB), and not by all
// builders (for example, the legacy PC-XT driver).
//
// - `<leftOption> <rightOption>` - Simulates pressing the ⌥ key. Supported
// only by certain keyboard drivers (such as VNC/USB), and not by all
// builders (for example, the legacy PC-XT driver).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants