Tough One: Any way to set Host Key Combination from command line?

Discussions about using Mac OS X guests (on Apple hardware) in VirtualBox.
Post Reply
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

Part of auto-configuring via shell commands, I'd like to set the Virtual Machine (Guest's) Host Key Combination shortcut via command line. This would affect VirtualBox itself.

Any way to do that?

Stephen
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Tough One: Any way to set Host Key Combination from command line?

Post by socratis »

There is no per-Guest HostKey. There's a per-Host HostKey, it's in the word itself! :)

Actually, to be 100% accurate, the HostKey is per-user, since it's stored in the VirtualBox Preferences file, VirtualBox.xml.

You issue the command:
  • 
    VBoxManage setextradata global "GUI/Input/HostKeyCombination" <ScanCode>
where "<ScanCode>" is the scan code of the key-of-interest. For example, the Right-Cmd key (which I personally use as the HostKey) is 54.

This can only be done for a specific user, locally. You don't get to do it remotely or if you send a VM to someone.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

I'm sending a VM to someone, but I'm having them DOWNLOAD the VirtualBox installer themselves, and I'm trying to eliminate as many steps as possible because they are unsophisticated users.

So I figured I would have them configure all these parameters via a .command executable command shell, that they just double-click.

As you know, if the HostKeyCombination is the command key -- it's a disaster for MacOS because, well, the Host usurps the Command key from the Guest.

It SEEMS that with keyboard and mouse capture working, there isn't the need to even have a HostKeyCombination. So maybe there's an easy way to set it to "none"?

Stephen
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Tough One: Any way to set Host Key Combination from command line?

Post by socratis »

SteveMacGeek wrote:As you know, if the HostKeyCombination is the command key -- it's a disaster for MacOS because, well, the Host usurps the Command key from the Guest.
And I gave you a perfectly legit alternative; the Right-Cmd. Nobody uses the Right-Cmd, unless in special circumstances.
SteveMacGeek wrote:So maybe there's an easy way to set it to "none"?
That would be a really counter-intuitive move. The HostKey is bound to a bunch of functionality, from resetting, to closing, to getting FullScreen, to... name it. You don't want to do that, trust me.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

The HostKey is bound to a bunch of functionality, from resetting, to closing, to getting FullScreen, to... name it.
So those are all functionality that my not-too-tech-savvy clients would never ever use.
Nobody uses the Right-Cmd, unless in special circumstances.
I'm with you -- but I'm also guessing that since there's no way for me to know what the scan code is for Right-Cmd, for the client (running the Guest), there's no way for me to pre-configure it using shell commands.

BTW -- could not locate VirtualBox.xml anywhere on the system.

Stephen
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Tough One: Any way to set Host Key Combination from command line?

Post by socratis »

You really need to pay closer attention to my messages:
SteveMacGeek wrote:since there's no way for me to know what the scan code is for Right-Cmd
socratis wrote:For example, the Right-Cmd key (which I personally use as the HostKey) is 54.
SteveMacGeek wrote:So those are all functionality that my not-too-tech-savvy clients would never ever use.
Let it be on your head then:
  • 
    VBoxManage setextradata global "GUI/Input/HostKeyCombination" 0
SteveMacGeek wrote:BTW -- could not locate VirtualBox.xml anywhere on the system.
You should have a searchable PDF included with your installation (Help » Contents). If not, there's the on-line manual in PDF format, again searchable. Take advantage of that fact, and use it to search the PDF for the terms that interest you.

Ch, 10.1. Where Oracle VM VirtualBox Stores its Files, "/Users/<you>/Library/VirtualBox/VirtualBox.xml" on OSX...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

I was paying attention.

On your computer that key is 54. On mine, it's 61. It'll be different on any keyboard with a different layout (I know you know this <g>)

My bad with not locating VirtualBox.xml. I was using spotlight to search including system folders, but spotlight indexing hadn't yet caught up and didn't locate VirtualBox.xml. Now it did!

I really wasn't being lazy: I had even looked in the on-line manual and PDF of same. But when I couldn't locate HostKeyCombinations, I posted.

I Really Do Appreciate all your expert advice. Thank you!

Best,

Stephen
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Tough One: Any way to set Host Key Combination from command line?

Post by socratis »

SteveMacGeek wrote:On your computer that key is 54. On mine, it's 61. It'll be different on any keyboard with a different layout (I know you know this <g>)
I was NOT aware of that! :o
What's your computer again? Actually what's your keyboard again?
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

What's your computer again? Actually what's your keyboard again?
The computer is an iMac 15,1 intel Core i7 (Retina 5K, 27-inch, Late 2014).

On the computer that is building the Host, the keyboard is a Model A1243 (product ID 0x024f) "Wired Aluminum USB Keyboard" -- that's the one with the attached keypad. US keyboard, of course.

When you said "scan code" -- I'm unfortunately familiar with the differences between scan codes, key code, and the unicode they generate. But without the actual keyboard, I'm not sure how to search for the scan code for any given keyboard. But scan codes are sooooo low-level, we try to avoid them. Except, of course, when you want to differentiate between a "left" command key and a "right" command key.

Stephen
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Tough One: Any way to set Host Key Combination from command line?

Post by socratis »

SteveMacGeek wrote:But without the actual keyboard, I'm not sure how to search for the scan code for any given keyboard.
Which would make it harder for what you want to do actually. If there are differences between the keyboards, which if I think about it for 2' it starts to make complete sense, then you have no other option but to include some instructions for your users.

Unless you want the "None" HostKey option, that's a universal zero (0). ;)
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

then you have no other option but to include some instructions for your users.
So my plan is to set it to "None", but include an optional section in the instructions on making some optimization choices: setting magnification, tweaking processors, setting up a file sharing connection, explaining the complex and twisted process to be able to capture and mount a USB thumb drive -- and the Host Key Combination.

Stephen
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

Here's a conundrum:

No matter what the Host Key Combination is, and even if the EXIT key combination for VirtualBox Manager is cleared, pressing COMMAND-Q in the Guest will cause the the Guest to display the shutdown options alert sheet.

That's frustrating for anyone running any Mac software in the Guest, because, of course, COMMAND-Q is usually mapped to Quit the running app.

Any magic on that? Or should this question be split off into a new thread?

Stephen
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Tough One: Any way to set Host Key Combination from command line?

Post by socratis »

SteveMacGeek wrote:Any magic on that?
No. The Cmd+Q as well as the Cmd+H are reserved and received by the Host. In that case if your Guest gets stuck you always have an exit strategy.
SteveMacGeek wrote:Or should this question be split off into a new thread?
The question is already answered ^^^, no need for a new thread.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
SteveMacGeek
Posts: 72
Joined: 15. Oct 2019, 22:11

Re: Tough One: Any way to set Host Key Combination from command line?

Post by SteveMacGeek »

The Cmd+Q as well as the Cmd+H are reserved and received by the Host. In that case if your Guest gets stuck you always have an exit strategy.
Well, the ultimate exit strategy is just force-quitting the VM. If you're "stuck", wouldn't that imply the VM isn't in a state where you would want to save and resume? You just want to forcibly shut it down.

But -- as I said -- it's not very friendly to force CMD+Q and CMD+H on a MacOS VM. They should be reassignable. (and maybe they are, just that Oracle doesn't document that).

Stephen
Post Reply