I prefer different modifier keybindings for my VM vs. native OS X, but VirtualBox (unlike VMWare/Parallels) passes the keyboard through to the VM natively without the ability to remap it on the way through.
Apparently one would normally use Karabiner to do all manner of trickery to remap keys per application etc. but support for this utility was broken in OS X Sierra. Instead, I use a pair of scripts:
-
switch.sh
uses the built-inhidutil
on OS X to remap modifier keys immediately when invoked -
init.lua
is a lua script run by Hammerspoon that subscribes to window switching events and callsswitch.sh
if it finds the VM window.
In OS X:
- Caps Lock -> Command
In the VM:
- Caps Lock -> Control
- Command -> Alt
- Alt -> Command
Because it doesn't work under this very specific set of conditions for this very specific set of problems.