Getting host to capture certain key presses in VirtualBox

49

11

I'm using VirtualBox on Ubuntu 9.10 with Windows XP as the guest OS.

It's pretty annoying that when I am in the guest OS - I can't switch virtual desktops (workspaces) on the host (Ubuntu) by pressing Control+Alt+(Left|Right|Up|Down) because VirtualBox captures those key combinations.

Is it possible to disable keyboard capture for some key combinations?

Alexander Smirnov

Posted 2010-02-14T17:16:53.483

Reputation: 536

Answers

28

While there are some Host Key shortcuts that activate certain VirtualBox functions (eg, Host Key+P which pauses the Guest), I don't know of any way to configure VirtualBox to send Host Key shortcuts to the Host OS.

However, since VirtualBox has an open source edition, it may be possible to modify the source code to add this feature. You can access the VirtualBox source code at the Download link.

In the meantime, you can use the Host Key to release the keyboard from the VirtualBox Guest's control. By default the Host Key is set to Right Ctrl. You can see the current Host Key in the VM window:

alt text

Just press the Host Key once to release the keyboard capture. After that, your Host OS will see your keypresses. So here's your workflow:

  1. Press and release the Host Key. Your Guest OS no longer captures keypresses.
  2. Press Ctrl+Alt+(Arrow key) to switch workspaces, or any other keys you want to send to the Host OS.

quack quixote

Posted 2010-02-14T17:16:53.483

Reputation: 37 382

It would be nice...But [Left Ctrl]+[Alt] does not work too...It is not depends on host key at all, VBox captures all key presses. – Alexander Smirnov – 2010-02-14T18:41:31.357

i'm sorry, i misread your question; i thought you had an Ubuntu guest on an XP host. updated the answer. – quack quixote – 2010-02-14T19:31:35.853

1Ok, thanks, I hope I'll find time for a little investigation to add this feature – Alexander Smirnov – 2010-02-14T21:25:24.730

@quack Gaff If one where to customize the source code. would that be easy to rebuild vmware to use it ? on a macos ? – momomo – 2019-08-04T22:47:43.023

15

This question is old, but I found a better solution that probably didn't exist back then.

You can disable "Auto capture keyboard" in Manager window -> File menu -> Preferences -> Input:

enter image description here

This disables the automatic keyboard grabbing completely, so window manager keybindings are passed directly to it.

In this mode, the 'host' key has the opposite effect - it enables grabbing instead of disabling it.

dequis

Posted 2010-02-14T17:16:53.483

Reputation: 250

1Works great! I fail to understand why this setting is not machine-specific though. – Franck Dernoncourt – 2014-11-07T18:36:19.623

Turns out this is actually a pretty good solution, if you're using the guest machine to run code you're developing on the host machine, even GUI code. If you don't maximise the GUI on the guest machine and keep the term/cmd for running the code open, you can hover/click the windows you want to type in, as you normally would for host windows (click-to-focus can be disabled in Windows!). Alt+Tab switches between VirtualBox and host windows, and keyboard shortcuts for switching workspaces will likely work (mine are configured as Super+arrow and Super+number, so I can't test Ctrl+Alt+arrow). – Michael Scheper – 2019-09-25T15:47:12.923

9The downside of this is that now you need to remember to enable keyboard capturing before you use things like Alt+Tab. Virtualbox really really needs a way to map and disable keyboard shortcuts inside the guest. – stackular – 2014-05-13T16:34:59.907

5

Pressing the host key (right-ctrl) once appears to allow the next key combination to go to the host machine.

For me, this means I can hit right-ctrl, release, then hit windows+left-ctrl+left to switch desktops

Curtis

Posted 2010-02-14T17:16:53.483

Reputation: 51

1This isn't actually disabling keyboard capture for some key combinations, this answer would be better as a comment. – Don't Root here plz... – 2016-05-19T15:30:38.763

Confirmed to work for the opposite combination: Windows 7 host + Ubuntu 16.04 guest. – jpaugh – 2017-09-05T15:36:10.087

1

I managed it very effectively by setting the host-key as the Win key! On Windows 10 you need Ctrl+Win+Arrows to switch desktops, and setting Win as host key makes you able to execute the combination directly on the host OS, but still capturing on the VM the other combination like Ctrl+C etc.

Andrea

Posted 2010-02-14T17:16:53.483

Reputation: 11

0

In Windows 10 Pro 1803 (with a Windows 7 VM in VirtualBox) pressing the host key and then whichever "host" keyboard shortcut also works for me. This allows me the minimal number of keyboard-only actions to switch desktops, starting from a "captured" VM, as per Curtis' suggestion.

It seems that if the host key includes the Windows key, that tends to pop up the Windows 7 start menu before going into "host" keyboard mode, so I changed my host key to be Ctrl-Shift-Alt which is single-hand friendly, then I can use the two hand shortcuts to switch desktops.

Donald Klopper

Posted 2010-02-14T17:16:53.483

Reputation: 1

0

I had the same problem, and could only solve it by

  • first disabling the Auto Capture Keyboard (which was enabled by default), in the File / Preferences / Input menu of VirtualBox
  • rebooting the VM
  • enabling again Auto Capture Keyboard
  • rebooting the VM

I suppose there is a bug in VirtualBox that ignores the initial settings.

Note: I rebooted after disabling the option, the first time I tried to solve the problem, thinking this was the solution (since it's often suggested). It didn't work so I enabled it again and that was fine. So I'm not sure this first reboot step is entirely necessary.

RedGlyph

Posted 2010-02-14T17:16:53.483

Reputation: 140