Index: trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk	(revision 35670)
+++ trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk	(revision 35686)
@@ -130,5 +130,6 @@
 	$(if $(VBOX_WITH_VDE),VBOX_WITH_VDE) \
 	$(if $(VBOX_WITH_EHCI),VBOX_WITH_EHCI) \
-	$(if $(VBOX_GUI_WITH_PIDFILE),VBOX_GUI_WITH_PIDFILE,)
+	$(if $(VBOX_GUI_WITH_PIDFILE),VBOX_GUI_WITH_PIDFILE) \
+	$(if $(VBOX_GUI_WITH_KEYS_RESET_HANDLER),VBOX_GUI_WITH_KEYS_RESET_HANDLER)
 ifdef VBOX_WITH_DEBUGGER_GUI
  VirtualBox_DEFS        += VBOX_WITH_DEBUGGER_GUI
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 35670)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 35686)
@@ -268,4 +268,53 @@
         emit keyboardStateChanged(keyboardState());
     }
+}
+
+void UIKeyboardHandler::releaseAllPressedKeys(bool aReleaseHostKey /* = true */)
+{
+    CKeyboard keyboard = session().GetConsole().GetKeyboard();
+    bool fSentRESEND = false;
+
+    /* Send a dummy scan code (RESEND) to prevent the guest OS from recognizing
+     * a single key click (for ex., Alt) and performing an unwanted action
+     * (for ex., activating the menu) when we release all pressed keys below.
+     * Note, that it's just a guess that sending RESEND will give the desired
+     * effect :), but at least it works with NT and W2k guests. */
+    for (uint i = 0; i < SIZEOF_ARRAY (m_pressedKeys); i++)
+    {
+        if (m_pressedKeys[i] & IsKeyPressed)
+        {
+            if (!fSentRESEND)
+            {
+                keyboard.PutScancode (0xFE);
+                fSentRESEND = true;
+            }
+            keyboard.PutScancode(i | 0x80);
+        }
+        else if (m_pressedKeys[i] & IsExtKeyPressed)
+        {
+            if (!fSentRESEND)
+            {
+                keyboard.PutScancode(0xFE);
+                fSentRESEND = true;
+            }
+            QVector <LONG> codes(2);
+            codes[0] = 0xE0;
+            codes[1] = i | 0x80;
+            keyboard.PutScancodes(codes);
+        }
+        m_pressedKeys[i] = 0;
+    }
+
+    if (aReleaseHostKey)
+        m_bIsHostkeyPressed = false;
+
+#ifdef Q_WS_MAC
+    /* Clear most of the modifiers: */
+    m_darwinKeyModifiers &=
+        alphaLock | kEventKeyModifierNumLockMask |
+        (aReleaseHostKey ? 0 : ::DarwinKeyCodeToDarwinModifierMask(m_globalSettings.hostKey()));
+#endif
+
+    emit keyboardStateChanged(keyboardState());
 }
 
@@ -1432,53 +1481,4 @@
 }
 
-void UIKeyboardHandler::releaseAllPressedKeys(bool aReleaseHostKey /* = true */)
-{
-    CKeyboard keyboard = session().GetConsole().GetKeyboard();
-    bool fSentRESEND = false;
-
-    /* Send a dummy scan code (RESEND) to prevent the guest OS from recognizing
-     * a single key click (for ex., Alt) and performing an unwanted action
-     * (for ex., activating the menu) when we release all pressed keys below.
-     * Note, that it's just a guess that sending RESEND will give the desired
-     * effect :), but at least it works with NT and W2k guests. */
-    for (uint i = 0; i < SIZEOF_ARRAY (m_pressedKeys); i++)
-    {
-        if (m_pressedKeys[i] & IsKeyPressed)
-        {
-            if (!fSentRESEND)
-            {
-                keyboard.PutScancode (0xFE);
-                fSentRESEND = true;
-            }
-            keyboard.PutScancode(i | 0x80);
-        }
-        else if (m_pressedKeys[i] & IsExtKeyPressed)
-        {
-            if (!fSentRESEND)
-            {
-                keyboard.PutScancode(0xFE);
-                fSentRESEND = true;
-            }
-            QVector <LONG> codes(2);
-            codes[0] = 0xE0;
-            codes[1] = i | 0x80;
-            keyboard.PutScancodes(codes);
-        }
-        m_pressedKeys[i] = 0;
-    }
-
-    if (aReleaseHostKey)
-        m_bIsHostkeyPressed = false;
-
-#ifdef Q_WS_MAC
-    /* Clear most of the modifiers: */
-    m_darwinKeyModifiers &=
-        alphaLock | kEventKeyModifierNumLockMask |
-        (aReleaseHostKey ? 0 : ::DarwinKeyCodeToDarwinModifierMask(m_globalSettings.hostKey()));
-#endif
-
-    emit keyboardStateChanged(keyboardState());
-}
-
 void UIKeyboardHandler::sendChangedKeyStates()
 {
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h	(revision 35670)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h	(revision 35686)
@@ -65,4 +65,5 @@
     void captureKeyboard(ulong uScreenId);
     void releaseKeyboard();
+    void releaseAllPressedKeys(bool aReleaseHostKey = true);
 
     /* Current keyboard state: */
@@ -129,5 +130,4 @@
     void fixModifierState(LONG *piCodes, uint *puCount);
     void saveKeyStates();
-    void releaseAllPressedKeys(bool aReleaseHostKey = true);
     void sendChangedKeyStates();
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 35670)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 35686)
@@ -46,4 +46,9 @@
 # endif
 #endif
+
+#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
+# include "UIKeyboardHandler.h"
+# include <signal.h>
+#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
 
 UISession::UISession(UIMachine *pMachine, CSession &sessionReference)
@@ -134,4 +139,12 @@
     /* Load uisession settings: */
     loadSessionSettings();
+
+#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
+    struct sigaction sa;
+    sa.sa_sigaction = &signalHandlerSIGUSR1;
+    sigemptyset(&sa.sa_mask);
+    sa.sa_flags = SA_RESTART | SA_SIGINFO;
+    sigaction(SIGUSR1, &sa, NULL);
+#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
 }
 
@@ -1036,2 +1049,20 @@
 }
 #endif
+
+#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
+/**
+ * Custom signal handler. When switching VTs, we might not get release events
+ * for Ctrl-Alt and in case a savestate is performed on the new VT, the VM will
+ * be saved with modifier keys stuck. This is annoying enough for introducing
+ * this hack.
+ */
+/* static */
+void UISession::signalHandlerSIGUSR1(int sig, siginfo_t * /* pInfo */, void * /*pSecret */)
+{
+    /* only SIGUSR1 is interesting */
+    if (sig == SIGUSR1)
+        if (UIMachine *pMachine = vboxGlobal().virtualMachine())
+            pMachine->uisession()->machineLogic()->keyboardHandler()->releaseAllPressedKeys();
+}
+#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
+
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 35670)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 35686)
@@ -31,4 +31,8 @@
 class QMenu;
 class QMenuBar;
+#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
+struct siginfo;
+typedef struct siginfo siginfo_t;
+#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
 
 /* Local forwards */
@@ -205,4 +209,8 @@
     void preparePowerUp();
 
+#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
+    static void signalHandlerSIGUSR1(int sig, siginfo_t *pInfo, void *pSecret);
+#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
+
     /* Private variables: */
     UIMachine *m_pMachine;
