Index: code/trunk/src/libraries/core/input/InputManager.cc
===================================================================
--- code/trunk/src/libraries/core/input/InputManager.cc	(revision 5781)
+++ code/trunk/src/libraries/core/input/InputManager.cc	(revision 5929)
@@ -41,8 +41,8 @@
 #include <boost/foreach.hpp>
 
+#include "util/Clock.h"
 #include "util/Convert.h"
 #include "util/Exception.h"
 #include "util/ScopeGuard.h"
-#include "core/Clock.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
@@ -53,5 +53,4 @@
 
 #include "InputBuffer.h"
-#include "KeyDetector.h"
 #include "JoyStick.h"
 #include "JoyStickQuantityListener.h"
@@ -88,7 +87,6 @@
         , oisInputManager_(0)
         , devices_(2)
-        , bExclusiveMouse_(false)
+        , mouseMode_(MouseMode::Nonexclusive)
         , emptyState_(0)
-        , keyDetector_(0)
         , calibratorCallbackHandler_(0)
     {
@@ -99,4 +97,6 @@
         this->setConfigValues();
 
+        if (GraphicsManager::getInstance().isFullScreen())
+            mouseMode_ = MouseMode::Exclusive;
         this->loadDevices();
 
@@ -105,13 +105,4 @@
         emptyState_->setHandler(&InputHandler::EMPTY);
         activeStates_[emptyState_->getPriority()] = emptyState_;
-
-        // KeyDetector to evaluate a pressed key's name
-        InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector);
-        // Create a callback to avoid buttonHeld events after the key has been detected
-        FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers);
-        bufferFunctor->setObject(this);
-        detector->setLeaveFunctor(bufferFunctor);
-        keyDetector_ = new KeyDetector();
-        detector->setHandler(keyDetector_);
 
         // Joy stick calibration helper callback
@@ -124,16 +115,8 @@
         this->updateActiveStates();
 
-        {
-            // calibrate console command
-            FunctorMember<InputManager>* functor = createFunctor(&InputManager::calibrate);
-            functor->setObject(this);
-            this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "calibrate"), true);
-        }
-        {
-            // reload console command
-            FunctorMember<InputManager>* functor = createFunctor(&InputManager::reload);
-            functor->setObject(this);
-            this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "reload"), false);
-        }
+        // calibrate console command
+        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::calibrate, this), "calibrate"), true);
+        // reload console command
+        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::reload, this), "reload"), false);
 
         CCOUT(4) << "Construction complete." << std::endl;
@@ -172,5 +155,5 @@
         paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
         paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
-        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+        if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
         {
             // Disable Windows key plus special keys (like play, stop, next, etc.)
@@ -185,5 +168,5 @@
         paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
 
-        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+        if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
         {
             if (CommandLine::getValue("keyboard_no_grab").getBool())
@@ -274,9 +257,4 @@
     }
 
-    void InputManager::setKeyDetectorCallback(const std::string& command)
-    {
-        this->keyDetector_->setCallbackCommand(command);
-    }
-
     // ############################################################
     // #####                    Destruction                   #####
@@ -289,9 +267,7 @@
 
         // Destroy calibrator helper handler and state
-        delete keyDetector_;
         this->destroyState("calibrator");
         // Destroy KeyDetector and state
-        delete calibratorCallbackHandler_;
-        this->destroyState("detector");
+        calibratorCallbackHandler_->destroy();
         // destroy the empty InputState
         this->destroyStateInternal(this->emptyState_);
@@ -528,9 +504,13 @@
 
         // Check whether we have to change the mouse mode
+        MouseMode::Value requestedMode = MouseMode::Dontcare;
         std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
-        if (mouseStates.empty() && bExclusiveMouse_ ||
-            !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_)
-        {
-            bExclusiveMouse_ = !bExclusiveMouse_;
+        if (mouseStates.empty())
+            requestedMode = MouseMode::Nonexclusive;
+        else 
+            requestedMode = mouseStates.front()->getMouseMode();
+        if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode)
+        {
+            mouseMode_ = requestedMode;
             if (!GraphicsManager::getInstance().isFullScreen())
                 this->reloadInternal();
@@ -722,5 +702,5 @@
         }
         statesByName_.erase(state->getName());
-        delete state;
+        state->destroy();
     }
 }
