Index: /trunk/include/VBox/pdm.h
===================================================================
--- /trunk/include/VBox/pdm.h	(revision 254)
+++ /trunk/include/VBox/pdm.h	(revision 255)
@@ -593,8 +593,8 @@
     /** Num Lock */
     PDMKEYBLEDS_NUMLOCK          = 0x0001,
+    /** Caps Lock */
+    PDMKEYBLEDS_CAPSLOCK         = 0x0002,
     /** Scroll Lock */
-    PDMKEYBLEDS_SCROLLLOCK       = 0x0002,
-    /** Caps Lock */
-    PDMKEYBLEDS_CAPSLOCK         = 0x0004
+    PDMKEYBLEDS_SCROLLLOCK       = 0x0004
 } PDMKEYBLEDS;
 
Index: /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 254)
+++ /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 255)
@@ -166,4 +166,5 @@
 static BOOL gfGuestScrollLockPressed = FALSE;
 static int  guGuestNumLockAdaptionCnt = 2;
+static int  guGuestCapsLockAdaptionCnt = 2;
 
 /** modifier keypress status (scancode as index) */
@@ -462,12 +463,14 @@
     }
 
-    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fScrollLock, BOOL fCapsLock)
+    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
     {
         /* Don't bother the guest with NumLock scancodes if he doesn't set the NumLock LED */
         if (gfGuestNumLockPressed != fNumLock)
             guGuestNumLockAdaptionCnt = 2;
+        if (gfGuestCapsLockPressed != fCapsLock)
+            guGuestCapsLockAdaptionCnt = 2;
         gfGuestNumLockPressed    = fNumLock;
+        gfGuestCapsLockPressed   = fCapsLock;
         gfGuestScrollLockPressed = fScrollLock;
-        gfGuestCapsLockPressed   = fCapsLock;
         return S_OK;
     }
@@ -2793,19 +2796,31 @@
     }
 
-    /*
-     * Some keyboards (e.g. the one of mine T60) don't send a NumLock scan code on every
-     * press of the key. Both the guest and the host should agree on the NumLock state.
-     * If they differ, we try to alter the guest NumLock state by sending the NumLock key
-     * scancode. We will get a feedback through the KBD_CMD_SET_LEDS command if the guest
-     * tries to set/clear the NumLock LED. If a (silly) guest doesn't change the LED, don't
-     * bother him with NumLock scancodes. At least our BIOS, Linux and Windows handle the
-     * NumLock LED well.
-     */
-    if (   guGuestNumLockAdaptionCnt
-        && (gfGuestNumLockPressed ^ !!(SDL_GetModState() & KMOD_NUM)))
-    {
-        guGuestNumLockAdaptionCnt--;
-        gKeyboard->PutScancode(0x45);
-        gKeyboard->PutScancode(0x45 | 0x80);
+    if (ev->type != SDL_KEYDOWN)
+    {
+        /*
+         * Some keyboards (e.g. the one of mine T60) don't send a NumLock scan code on every
+         * press of the key. Both the guest and the host should agree on the NumLock state.
+         * If they differ, we try to alter the guest NumLock state by sending the NumLock key
+         * scancode. We will get a feedback through the KBD_CMD_SET_LEDS command if the guest
+         * tries to set/clear the NumLock LED. If a (silly) guest doesn't change the LED, don't
+         * bother him with NumLock scancodes. At least our BIOS, Linux and Windows handle the
+         * NumLock LED well.
+         */
+        if (   guGuestNumLockAdaptionCnt
+            && (gfGuestNumLockPressed ^ !!(SDL_GetModState() & KMOD_NUM)))
+        {
+            guGuestNumLockAdaptionCnt--;
+            gKeyboard->PutScancode(0x45);
+            gKeyboard->PutScancode(0x45 | 0x80);
+        }
+#if 0  /* For some reason SDL_GetModState() does not return KMOD_CAPS correctly */
+        if (   guGuestCapsLockAdaptionCnt
+            && (gfGuestCapsLockPressed ^ !!(SDL_GetModState() & KMOD_CAPS)))
+        {
+            guGuestCapsLockAdaptionCnt--;
+            gKeyboard->PutScancode(0x3a);
+            gKeyboard->PutScancode(0x3a | 0x80);
+        }
+#endif
     }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h	(revision 254)
+++ /trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h	(revision 255)
@@ -200,4 +200,5 @@
     bool mfCapsLock;
     long muNumLockAdaptionCnt;
+    long muCapsLockAdaptionCnt;
 
     QTimer *resize_hint_timer;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 254)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 255)
@@ -198,12 +198,12 @@
 {
 public:
-    ModifierKeyChangeEvent(bool fNumLock, bool fScrollLock, bool fCapsLock) :
+    ModifierKeyChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock) :
         QEvent ((QEvent::Type) VBoxDefs::ModifierKeyChangeEventType),
-        mfNumLock(fNumLock), mfScrollLock(fScrollLock), mfCapsLock(fCapsLock) {}
+        mfNumLock(fNumLock), mfCapsLock(fCapsLock), mfScrollLock(fScrollLock) {}
     bool NumLock()    const { return mfNumLock; }
+    bool CapsLock()   const { return mfCapsLock; }
     bool ScrollLock() const { return mfScrollLock; }
-    bool CapsLock()   const { return mfCapsLock; }
 private:
-    bool mfNumLock, mfScrollLock, mfCapsLock;
+    bool mfNumLock, mfCapsLock, mfScrollLock;
 };
 
@@ -292,8 +292,8 @@
     }
 
-    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fScrollLock, BOOL fCapsLock)
+    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
     {
         QApplication::postEvent (
-            view, new ModifierKeyChangeEvent (fNumLock, fScrollLock, fCapsLock));
+            view, new ModifierKeyChangeEvent (fNumLock, fCapsLock, fScrollLock));
         return S_OK;
     }
@@ -350,4 +350,5 @@
     , autoresize_guest (false)
     , muNumLockAdaptionCnt (2)
+    , muCapsLockAdaptionCnt (2)
     , mode (rm)
 {
@@ -784,7 +785,9 @@
                 if (me->NumLock() != mfNumLock)
                     muNumLockAdaptionCnt = 2;
+                if (me->CapsLock() != mfCapsLock)
+                    muCapsLockAdaptionCnt = 2;
                 mfNumLock    = me->NumLock();
+                mfCapsLock   = me->CapsLock();
                 mfScrollLock = me->ScrollLock();
-                mfCapsLock   = me->CapsLock();
                 return true;
             }
@@ -1289,6 +1292,4 @@
 void VBoxConsoleView::FixModifierState(LONG *codes, uint *count)
 {
-    unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0, uKeyMaskScroll = 0;
-
 #if defined(Q_WS_X11)
 
@@ -1296,4 +1297,5 @@
     int      iDummy3, iDummy4, iDummy5, iDummy6;
     unsigned uMask;
+    unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0, uKeyMaskScroll = 0;
 
     uKeyMaskCaps          = LockMask;
@@ -1321,4 +1323,10 @@
         codes[(*count)++] = 0x45 | 0x80;
     }
+    if (muCapsLockAdaptionCnt && (mfCapsLock ^ !!(uMask & uKeyMaskCaps)))
+    {
+        muCapsLockAdaptionCnt--;
+        codes[(*count)++] = 0x3a;
+        codes[(*count)++] = 0x3a | 0x80;
+    }
 
 #elif defined(Q_WS_WIN32)
@@ -1329,4 +1337,10 @@
         codes[(*count)++] = 0x45;
         codes[(*count)++] = 0x45 | 0x80;
+    }
+    if (muCapsLockAdaptionCnt && (mfCapsLock ^ !!(GetKeyState(VK_CAPITAL))))
+    {
+        muCapsLockAdaptionCnt--;
+        codes[(*count)++] = 0x3a;
+        codes[(*count)++] = 0x3a | 0x80;
     }
 
@@ -1388,4 +1402,12 @@
         else
         {
+            if (flags & KeyPressed)
+            {
+                // Check if the guest has the same view on the modifier keys (NumLock,
+                // CapsLock, ScrollLock) as the X server. If not, send KeyPress events
+                // to synchronize the state.
+                FixModifierState (codes, &count);
+            }
+
             // process the scancode and update the table of pressed keys
             uint8_t what_pressed = IsKeyPressed;
@@ -1415,10 +1437,4 @@
             else
                 keys_pressed [scan] &= ~IsKbdCaptured;
-
-            // Check if the guest has the same view on the modifier keys (NumLock,
-            // CapsLock, ScrollLock) as the X server. If not, send KeyPress events
-            // to synchronize the state.
-            FixModifierState (codes, &count);
-            
         }
     }
Index: /trunk/src/VBox/Main/include/DisplayImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/DisplayImpl.h	(revision 254)
+++ /trunk/src/VBox/Main/include/DisplayImpl.h	(revision 255)
@@ -97,5 +97,5 @@
     }
 
-    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fScrollLock, BOOL fCapsLock)
+    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
     {
         return S_OK;
