diff --git a/indra/llwindow/llkeyboard.cpp b/indra/llwindow/llkeyboard.cpp
index 5404ac50e5c5baefe53ec7e2f65bf6b5d0604388..e65cc7563e6a7010e1ffe54a0c5ab82342dd77a5 100644
--- a/indra/llwindow/llkeyboard.cpp
+++ b/indra/llwindow/llkeyboard.cpp
@@ -148,6 +148,22 @@ void LLKeyboard::addKeyName(KEY key, const std::string& name)
 	sNamesToKeys[nameuc] = key;
 }
 
+void LLKeyboard::resetKeyDownAndHandle()
+{
+    MASK mask = currentMask(FALSE);
+    for (S32 i = 0; i < KEY_COUNT; i++)
+    {
+        if (mKeyLevel[i])
+        {
+            mKeyDown[i] = FALSE;
+            mKeyLevel[i] = FALSE;
+            mKeyUp[i] = TRUE;
+            mCurTranslatedKey = (KEY)i;
+            mCallbacks->handleTranslatedKeyUp(i, mask);
+        }
+    }
+}
+
 // BUG this has to be called when an OS dialog is shown, otherwise modifier key state
 // is wrong because the keyup event is never received by the main window. JC
 void LLKeyboard::resetKeys()
diff --git a/indra/llwindow/llkeyboard.h b/indra/llwindow/llkeyboard.h
index 36bd8bcbed54784c4721f793f8e05dc19aeb2313..fb1ae10f50b6b21ff66a452f3c10d0dbacec23ce 100644
--- a/indra/llwindow/llkeyboard.h
+++ b/indra/llwindow/llkeyboard.h
@@ -58,7 +58,8 @@ class LLKeyboard
 	LLKeyboard();
 	virtual ~LLKeyboard();
 
-	void			resetKeys();
+    void			resetKeyDownAndHandle();
+    void			resetKeys();
 
 
 	F32				getCurKeyElapsedTime()	{ return getKeyDown(mCurScanKey) ? getKeyElapsedTime( mCurScanKey ) : 0.f; }
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 1381272cadebbd442dc3400ff7f2eb6b0bb0efaf..3c9a10bb2e90ff1185919108a193f57fde20c7da 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -1573,9 +1573,11 @@ void LLViewerWindow::handleFocusLost(LLWindow *window)
 	showCursor();
 	getWindow()->setMouseClipping(FALSE);
 
-	// If losing focus while keys are down, reset them.
+	// If losing focus while keys are down, handle them as
+    // an 'up' to correctly release states, then reset states
 	if (gKeyboard)
 	{
+        gKeyboard->resetKeyDownAndHandle();
 		gKeyboard->resetKeys();
 	}