Remap "left-command" key to code for Alt

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
JimH44
Posts: 4
Joined: 13. May 2022, 11:15

Remap "left-command" key to code for Alt

Post by JimH44 »

Hello,
I am happily running Virtualbox 6.1.34 r150636 on a MacBook Prleft-o using the Big Sur version of macos (11.6.5) as the host OS (64-bit, 64G RAM).
I have specified the right-option key as the Host key for VBox, with the result that I can use right-option+f to go full-screen, right-option-p to Pause/UnPause the guest operating system, and so on.
I run a Windows 10 guest on this system (64-bit, 8G RAM), and I am in the process of setting up an Ubuntu Linux guest (64-bit, 8G RAM).

The "left-command" key is in the same position as the Alt key on a Windows computer's keyboard, namely just to the left of the space bar. In this post I'll call the key just to the left of the spacebar "JLoSB", short for "Just Left of SpaceBar".

In macos, Windows and Linux, I can hold down JLoSB and tap the Tab key repeatedly to switch between running applications (called Alt-Tabbing in the Windows world.)
When I am using VirtualBox and a guest operating system has keyboard focus and I want to switch to another application running in the guest OS, if I do what my fingers do automatically, namely JLoSB-Tab, this switches not to another application in the guest OS but to another application running on the host macos system. Not what I wanted.
If I want to Alt-tab between processes running in the guest machine, I have to use the next key across, namely "option". That is, I need to "option-Tab" between applications running in the guest. This means that I have to keep thinking "Am I talking to the guest or to the host" whenever I want to switch to another application running in the current OS. I would like to change that, hence this post.

Another problem is that when I hold down the JLoSB key and tap Tab, I get to the other processes running in the host and when I JLoSB-Tab back to the VB guest, I find that the START menu is open, because the guest had interpreted my long-press on the JLoSB key as a press on the Windows key. It seems this happens because VB changes the code coming from the JLoSB key to the code for the Windows key. I then have to tap the Esc key to close the start menu before I can type into the guest application or option-tab to a different application in the guest.

I would like to be able to ask VB to remap left-command to the Windows/Linux code for "Alt" instead of the code for the Windows/Super key. I would then use right-command as the Windows/Super key as it is at present, to open the START menu in the guest OS or to do Windows-D to show the Desktop or Windows-R to open the Run dialog.

How then to command/Alt-Tab from a guest application to a host application? Perhaps with Host-Tab (in my case, right-option-Tab).

Can anyone point me to a way of doing the remapping that I want to do?

With the guest OS in focus, I can Host+C to sCale the view and reveal the VirtualBox menu at the top of the screen and do VirtualBox->Preferences and click the keyboard icon to get the keyboard control section. In that dialog I can change the Host key or set the combination for Full-screen or sCaled view etc, but couldn't find any way to make left-command produce the Alt key's code instead of the code for the Windows/Super key.

If the remapping I want to do is not possible, how could I suggest this to the developers, or get their attention and discuss it with them?

Thanks for thinking about these things,
Jim
Attachments
Log-2022-05-14.txt
Log file with Windows guest running, truncated to fit
(110.12 KiB) Downloaded 4 times
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Remap "left-command" key to code for Alt

Post by fth0 »

First of all, there's one mistake in your interpretation: The left Cmd key is the left Win key. So you're really "Win-Tabbing" and not "Alt-Tabbing". ;) This will also explain several of your other observations.

Regarding your general problem, I can recommend a very powerful Mac tool named Karabiner Elements. It especially gives you the power to interpret keys differently depending on the current application. For example, you could switch the left Option/Alt key with the left Cmd/Win key only when sending them to applications that lead to Windows/Linux systems (e.g. VirtualBox, TeamViewer, Microsoft Remote Desktop, VNC). You could also simulate non-existing keys (e.g. right Ctrl, SysReq) and "move" special characters (e.g. "@", "€", "~") to suit your muscle memory.
JimH44 wrote:How then to command/Alt-Tab from a guest application to a host application? Perhaps with Host-Tab (in my case, right-option-Tab).
Press and release the Host key alone, then use Cmd-Tab.
JimH44
Posts: 4
Joined: 13. May 2022, 11:15

Re: Remap "left-command" key to code for Alt

Post by JimH44 »

Thanks, fth0, for the suggestion.
I'll try Karabiner-Elements.
JimH44
Posts: 4
Joined: 13. May 2022, 11:15

Re: Remap "left-command" key to code for Alt

Post by JimH44 »

Thanks again, fth0.
I have enabled left-command to produce left-option when VirtualBox is running :-)
Now when I am running Windows 10 in VirtualBox on my MacBook Pro, I can left-command-tab between running Windows apps.

But I must say I was surprised that I had to download a complex keymap that did something when World of Warcraft was running, and then locate the JSON file and edit it to change the key names and the application name. I didn't think I would need to go under the hood like that on a Mac to achieve a purpose like that.

Now when I want to "Alt-tab" from the Windows environment back to a Mac program, I can use right-command-tab to do that. But it still has the effect in the Windows client of opening the START menu, as happens when you tap the Windows key. (This means that when I command-tab back to the Windows environment, I still have to tap Esc to close the start menu.) But I have found that I can do a 3-finger swipe to the left to get the previous Mac screen without that unwanted side effect.

By the way, your suggestion
Press and release the Host key alone, then use Cmd-Tab.
didn't work for me. It puts the Windows client's screen into a strange state that I didn't recognise.

Thanks again, I'm a happy camper now :-)
JimH44
Posts: 4
Joined: 13. May 2022, 11:15

Re: Remap "left-command" key to code for Alt

Post by JimH44 »

I have since realised that the "three-finger swipe to left or right" that I had mentioned before changes to a different "workspace" in macos. (Four-finger swipes left or right have the same effect.) (Workspaces are like the different desktops available in Linux GUI systems.)

To see the workspaces, swipe up with three fingers and they appear in the bar at the top, with the VB client running in its own workspace. Swipe down again to re-enter the workspace you were in before.

It seems that this works because VirtualBox runs the client in a new "workspace" automatically, so the three-finger swipe lets me sweep between client and host and back again without opening the START menu in the windows system. Very clever of you, VB designers!
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Remap "left-command" key to code for Alt

Post by fth0 »

JimH44 wrote:It seems that this works because VirtualBox runs the client in a new "workspace" automatically, so the three-finger swipe lets me sweep between client and host and back again without opening the START menu in the windows system. Very clever of you, VB designers!
You'll rather have to thank the Apple designers IMO. What you describe is the standard macOS behavior for full-screen applications, and you've configured VirtualBox to run the VM in full-screen.
Post Reply