The dangers of virtual machines

Virtual machines are great, don’t get me wrong. For example, I downloaded this weekend the iso of Crunch Bang Linux, an Ubuntu based distro that looks very slick and geeky friendly and instead of installing it on an actual computer I just created a new VM on VirtualBox to get a feeling before going for the real thing. So here the VM is really good because it gives a safe environment to test without risk. (BTW, Crunch Bang might well replace Ubuntu as my main distro in the very near future).

BUT using a VM for development adds an extra layer of complexity that can cause trouble as yours truly can testify. Just to put everybody in context, I develop Flash these days on a virtual Windows XP hosted by an Ubuntu box running on an iMac. To be honest, some days I’m amazed that things run at all.

So, for the project I’m about to finish I had to detect a long key press. That’s:

- Press & release ESC key: do something
- Press & hold ESC key: do something else

I thought about setting either a timer or a counter when the key goes down and check when it goes up. No rocket science here, right? Added some listeners and to my surprise the UP event was being fired just after the DOWN event even with the key pressed… Long story short: this weird thing only happens on the virtual XP. If I try the same application on the native Linux things behave as expected.

When I first encountered the problem I posted it on StackOverflow (AS3: Detect long key presses) but couldn’t come back to the problem until now. Reviewing the answers this bit put me in the road to find out the real problem:

I guess it’s also possible, though unlikely, your keyboard’s sending “up” messages to the OS when it shouldn’t be

Unlikely as it looked, that was the problem. I’m really happy I didn’t waste a lot of time figuring out what was going on, but I reckon this could have been one of those little things that holds you for hours banging your head against the wall.

So kids, be warned about the dangers of virtual machines.

Leave a Reply