Defining custom keyboard shortcuts

This is for discussing general topics about how to use VirtualBox.
Post Reply
virboxer
Posts: 4
Joined: 21. Apr 2021, 10:54

Defining custom keyboard shortcuts

Post by virboxer »

Hi, i'd like to define custom keyboard shortcuts so that when i press some key combination (eg Alt + G) it would behave as if my guest OS has captured Alt + Tab. Is it possible?

Edit.: Capturing Alt + Tag from guest os instead of host os would also be an acceptable solution.

Host: Debian 10
Guest: Windows 10
VirtualBox: 6.1.6 r137129 (Qt5.11.3) (I'm willing to update that one if that helps)
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Defining custom keyboard shortcuts

Post by scottgus1 »

You could inspect the list of available commands in the main Virtualbox window's File menu, Preferences, Input to see if something might work for you. But to the best of my knowledge, if the host OS grabs a certain key combo, it does so before Virtualbox could get the combo. So no way to pass Alt-Tab if Alt-Tab is grabbed by the host OS first.

However, there is a vboxmanage command to pass keyboard scan codes into a VM:

vboxmanage controlvm "vm name" keyboardputscancode <hex> ....

which can put key movements into the VM. So you might be able to send 'alt down' 'tab down' 'tab up' 'alt up' codes to the VM. These won't get caught by the host OS (I think) and the command can be launched by a batch file or script that can be started with a custom host OS keyboard shortcut.
virboxer
Posts: 4
Joined: 21. Apr 2021, 10:54

Re: Defining custom keyboard shortcuts

Post by virboxer »

scottgus1 wrote:You could inspect the list of available commands in the main Virtualbox window's File menu, Preferences, Input to see if something might work for you. But to the best of my knowledge, if the host OS grabs a certain key combo, it does so before Virtualbox could get the combo. So no way to pass Alt-Tab if Alt-Tab is grabbed by the host OS first.

However, there is a vboxmanage command to pass keyboard scan codes into a VM:

vboxmanage controlvm "vm name" keyboardputscancode <hex> ....

which can put key movements into the VM. So you might be able to send 'alt down' 'tab down' 'tab up' 'alt up' codes to the VM. These won't get caught by the host OS (I think) and the command can be launched by a batch file or script that can be started with a custom host OS keyboard shortcut.
Thanks, this surely can be very useful command, but after a while of playing with it i've realized that i can use "Ctrl + Alt + Tab" which is close enough to what i need and even though it's also in use by default in gnome, it can be remapped.

Anyway, for the future lurkers, other useful usage of this command would be Alt + F4

Code: Select all

# (left alt key press; F4 key press; left alt key down; F4 key down
vboxmanage controlvm "vm name" keyboardputscancode 38 3e b8 be
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Defining custom keyboard shortcuts

Post by scottgus1 »

Great, thanks for telling us your solution!
Post Reply