Sunday, May 11, 2008

VMware keyboard annoyances on Ubuntu 8.04 (Hardy)

Like several other people I've had issues with my keyboard modifiers (shift, alt, ctrl, etc.) when switching from the guest OS (Windows) back to the host (Linux). Apparently, the easiest fix for this is to use the gnome keyboard layout gui to briefly switch the keyboard map to something random, then back to the original layout. So, here is a short perl script that does the same using the setxkbmap utility. If you want to use it, make sure to change the $orig_kb_map variable to match your keyboard model. You can create an application launcher on your Desktop or panel and simply click it regain control of your keyboard modifiers. Until there is an official fix for this bug, this is at least bearable.

#!/usr/bin/perl

# vmkbfix: a script to reset the keyboard layout after switching out of
# a virtual machine.

use strict;
use warnings;

my $orig_kb_model = "pc101"; # The keyboard model
my $switch_kb_model = "pc104"; # The model to switch to briefly
my $SETXKBMAP = "/usr/bin/setxkbmap"; # location of setxkbmap

# briefly switching to a different keyboard model, then switching back
`$SETXKBMAP -model $switch_kb_model`;
`$SETXKBMAP -model $orig_kb_model`;

1 comment:

Johan Rex said...

This doesn't restore Alt-Tab functionality for me. Everything else works though.