Index: code/trunk/src/core/input/Button.cc
===================================================================
--- code/trunk/src/core/input/Button.cc	(revision 3370)
+++ code/trunk/src/core/input/Button.cc	(revision 5695)
@@ -59,5 +59,4 @@
         nCommands_[1]=0;
         nCommands_[2]=0;
-        this->configContainer_ = 0;
     }
 
Index: code/trunk/src/core/input/InputManager.cc
===================================================================
--- code/trunk/src/core/input/InputManager.cc	(revision 3370)
+++ code/trunk/src/core/input/InputManager.cc	(revision 5695)
@@ -41,4 +41,5 @@
 #include <boost/foreach.hpp>
 
+#include "util/Convert.h"
 #include "util/Exception.h"
 #include "util/ScopeGuard.h"
@@ -49,4 +50,5 @@
 #include "core/CommandLine.h"
 #include "core/Functor.h"
+#include "core/GraphicsManager.h"
 
 #include "InputBuffer.h"
@@ -82,9 +84,9 @@
     // ##########                                        ##########
     // ############################################################
-    InputManager::InputManager(size_t windowHnd)
+    InputManager::InputManager()
         : internalState_(Bad)
         , oisInputManager_(0)
         , devices_(2)
-        , windowHnd_(0)
+        , bExclusiveMouse_(false)
         , emptyState_(0)
         , keyDetector_(0)
@@ -97,5 +99,5 @@
         this->setConfigValues();
 
-        this->loadDevices(windowHnd);
+        this->loadDevices();
 
         // Lowest priority empty InputState
@@ -147,6 +149,4 @@
         Creates the OIS::InputMananger, the keyboard, the mouse and
         the joys ticks. If either of the first two fail, this method throws an exception.
-    @param windowHnd
-        The window handle of the render window
     @param windowWidth
         The width of the render window
@@ -154,7 +154,7 @@
         The height of the render window
     */
-    void InputManager::loadDevices(size_t windowHnd)
-    {
-        CCOUT(3) << "Loading input devices..." << std::endl;
+    void InputManager::loadDevices()
+    {
+        CCOUT(4) << "Loading input devices..." << std::endl;
 
         // When loading the devices they should not already be loaded
@@ -164,28 +164,40 @@
         assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
 
-        // store handle internally so we can reload OIS
-        windowHnd_ = windowHnd;
-
+        // Fill parameter list
         OIS::ParamList paramList;
-        std::ostringstream windowHndStr;
-
-        // Fill parameter list
-        windowHndStr << static_cast<unsigned int>(windowHnd);
-        paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
+        size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle();
+        paramList.insert(std::make_pair("WINDOW", multi_cast<std::string>(windowHnd)));
 #if defined(ORXONOX_PLATFORM_WINDOWS)
-        //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
-        //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
-        //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
-        //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
+        paramList.insert(std::make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
+        paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
+        paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
+        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+        {
+            // Disable Windows key plus special keys (like play, stop, next, etc.)
+            paramList.insert(std::make_pair("w32_keyboard", "DISCL_NOWINKEY"));
+            paramList.insert(std::make_pair("w32_mouse", "DISCL_EXCLUSIVE"));
+        }
+        else
+            paramList.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE"));
 #elif defined(ORXONOX_PLATFORM_LINUX)
-        paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
-        paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
-        paramList.insert(std::make_pair(std::string("x11_mouse_hide"), "true"));
-        bool kbNoGrab;
-        CommandLine::getValue("keyboard_no_grab", &kbNoGrab);
-        if (kbNoGrab)
-            paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
+        // Enabling this is probably a bad idea, but whenever orxonox crashes, the setting stays on
+        // Trouble might be that the Pressed event occurs a bit too often...
+        paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
+
+        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+        {
+            if (CommandLine::getValue("keyboard_no_grab").getBool())
+                paramList.insert(std::make_pair("x11_keyboard_grab", "false"));
+            else
+                paramList.insert(std::make_pair("x11_keyboard_grab", "true"));
+            paramList.insert(std::make_pair("x11_mouse_grab",  "true"));
+            paramList.insert(std::make_pair("x11_mouse_hide", "true"));
+        }
         else
-            paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("true")));
+        {
+            paramList.insert(std::make_pair("x11_keyboard_grab", "false"));
+            paramList.insert(std::make_pair("x11_mouse_grab",  "false"));
+            paramList.insert(std::make_pair("x11_mouse_hide", "false"));
+        }
 #endif
 
@@ -212,5 +224,4 @@
         }
 
-        // TODO: Remove the two parameters
         this->loadMouse();
         this->loadJoySticks();
@@ -219,5 +230,5 @@
         this->updateActiveStates();
 
-        CCOUT(3) << "Input devices loaded." << std::endl;
+        CCOUT(4) << "Input devices loaded." << std::endl;
     }
 
@@ -275,5 +286,5 @@
     InputManager::~InputManager()
     {
-        CCOUT(4) << "Destroying..." << std::endl;
+        CCOUT(3) << "Destroying..." << std::endl;
 
         // Destroy calibrator helper handler and state
@@ -293,5 +304,5 @@
             this->destroyDevices();
 
-        CCOUT(4) << "Destruction complete." << std::endl;
+        CCOUT(3) << "Destruction complete." << std::endl;
     }
 
@@ -304,5 +315,5 @@
     void InputManager::destroyDevices()
     {
-        CCOUT(3) << "Destroying devices..." << std::endl;
+        CCOUT(4) << "Destroying devices..." << std::endl;
 
         BOOST_FOREACH(InputDevice*& device, devices_)
@@ -336,5 +347,5 @@
 
         internalState_ |= Bad;
-        CCOUT(3) << "Destroyed devices." << std::endl;
+        CCOUT(4) << "Destroyed devices." << std::endl;
     }
 
@@ -365,9 +376,9 @@
 
         this->destroyDevices();
-        this->loadDevices(windowHnd_);
+        this->loadDevices();
 
         internalState_ &= ~Bad;
         internalState_ &= ~ReloadRequest;
-        CCOUT(3) << "Reloading complete." << std::endl;
+        CCOUT(4) << "Reloading complete." << std::endl;
     }
 
@@ -481,4 +492,5 @@
     void InputManager::updateActiveStates()
     {
+        assert((internalState_ & InputManager::Ticking) == 0);
         // temporary resize
         for (unsigned int i = 0; i < devices_.size(); ++i)
@@ -512,4 +524,14 @@
         for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
             activeStatesTicked_.push_back(*it);
+
+        // Check whether we have to change the mouse mode
+        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
+        if (mouseStates.empty() && bExclusiveMouse_ ||
+            !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_)
+        {
+            bExclusiveMouse_ = !bExclusiveMouse_;
+            if (!GraphicsManager::getInstance().isFullScreen())
+                this->reloadInternal();
+        }
     }
 
@@ -556,6 +578,18 @@
     }
 
-    // ############################################################
-    // #####                    Iput States                   #####
+    std::pair<int, int> InputManager::getMousePosition() const
+    {
+        Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]);
+        if (mouse != NULL)
+        {
+            const OIS::MouseState state = mouse->getOISDevice()->getMouseState();
+            return std::make_pair(state.X.abs, state.Y.abs);
+        }
+        else
+            return std::make_pair(0, 0);
+    }
+
+    // ############################################################
+    // #####                    Input States                  #####
     // ##########                                        ##########
     // ############################################################
Index: code/trunk/src/core/input/InputManager.h
===================================================================
--- code/trunk/src/core/input/InputManager.h	(revision 3370)
+++ code/trunk/src/core/input/InputManager.h	(revision 5695)
@@ -84,5 +84,5 @@
             the constructor fails with an std::exception.
         */
-        InputManager(size_t windowHnd);
+        InputManager();
         //! Destroys all devices AND all input states!
         ~InputManager();
@@ -167,6 +167,6 @@
             { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
         //! Returns a pointer to the OIS InputManager. Only you if you know what you're doing!
-        OIS::InputManager* getOISInputManager()
-            { return this->oisInputManager_; }
+        OIS::InputManager* getOISInputManager() { return this->oisInputManager_; }
+        std::pair<int, int> getMousePosition() const;
 
     private: // functions
@@ -175,5 +175,5 @@
 
         // Intenal methods
-        void loadDevices(size_t windowHnd);
+        void loadDevices();
         void loadMouse();
         void loadJoySticks();
@@ -193,6 +193,5 @@
         OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
         std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
-        // TODO: Get this from the GraphicsManager during reload
-        size_t                              windowHnd_;            //!< Render window handle (used to reload the InputManager)
+        bool                                bExclusiveMouse_;      //!< Currently applied mouse mode
 
         // some internally handled states and handlers
Index: code/trunk/src/core/input/InputState.cc
===================================================================
--- code/trunk/src/core/input/InputState.cc	(revision 3370)
+++ code/trunk/src/core/input/InputState.cc	(revision 5695)
@@ -37,4 +37,5 @@
         , bAlwaysGetsInput_(bAlwaysGetsInput)
         , bTransparent_(bTransparent)
+        , bExclusiveMouse_(true)
         , bExpired_(true)
         , handlers_(2)
Index: code/trunk/src/core/input/InputState.h
===================================================================
--- code/trunk/src/core/input/InputState.h	(revision 3370)
+++ code/trunk/src/core/input/InputState.h	(revision 5695)
@@ -75,6 +75,5 @@
           not influence ony other InputState at all.
 
-        Priorities
-        **********
+    @par Priorities
         Every InputState has a priority when on the stack, but mostly this
         priority is dynamic (InputStatePriority::Dynamic) which means that a state
@@ -83,4 +82,11 @@
         a high priority (InputStatePriority::HighPriority). These 'special' ones
         are used for features like the KeyDetector or the console. Use with care!
+
+    @par Exclusive/Non-Exclusive mouse Mode
+        You can select a specific mouse mode that tells whether the application
+        should have exclusive accessto it or not.
+        When in non-exclusive mode, you can move the mouse out of the window
+        like with any other normal window (only for windowed mode!).
+        The setting is dictated by the topmost InputState that gets mouse events.
     */
     class _CoreExport InputState : public JoyStickQuantityListener
@@ -114,4 +120,7 @@
         void setHandler        (InputHandler* handler);
 
+        void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }
+        bool getIsExclusiveMouse() const { return bExclusiveMouse_; }
+
         //! Returns the name of the state (which is unique!)
         const std::string& getName() const { return name_; }
@@ -165,4 +174,5 @@
         const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
         const bool                  bTransparent_;          //!< See class declaration for explanation
+        bool                        bExclusiveMouse_;       //!< See class declaration for explanation
         int                         priority_;              //!< Current priority (might change)
         bool                        bExpired_;              //!< See hasExpired()
Index: code/trunk/src/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/core/input/KeyBinder.cc	(revision 3370)
+++ code/trunk/src/core/input/KeyBinder.cc	(revision 5695)
@@ -55,7 +55,4 @@
         mousePosition_[0] = 0;
         mousePosition_[1] = 0;
-
-        joyStickButtons_.reserve(1000);
-        joyStickAxes_.reserve(1000);
 
         RegisterRootObject(KeyBinder);
@@ -167,7 +164,7 @@
             {
                 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
-                    joyStickButtons_[iDev][i].readConfigValue(this->configFile_);
+                    (*joyStickButtons_[iDev])[i].readConfigValue(this->configFile_);
                 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
-                    joyStickAxes_[iDev][i].readConfigValue(this->configFile_);
+                    (*joyStickAxes_[iDev])[i].readConfigValue(this->configFile_);
             }
         }
@@ -179,4 +176,9 @@
     void KeyBinder::initialiseJoyStickBindings()
     {
+        while (joyStickAxes_.size() < joySticks_.size())
+            joyStickAxes_.push_back(shared_ptr<JoyStickAxisVector>(new JoyStickAxisVector()));
+        while (joyStickButtons_.size() < joySticks_.size())
+            joyStickButtons_.push_back(shared_ptr<JoyStickButtonVector>(new JoyStickButtonVector()));
+        // For the case the new size is smaller
         this->joyStickAxes_.resize(joySticks_.size());
         this->joyStickButtons_.resize(joySticks_.size());
@@ -189,18 +191,18 @@
             for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
             {
-                joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i];
-                joyStickButtons_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
-                joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName;
+                (*joyStickButtons_[iDev])[i].name_ = JoyStickButtonCode::ByString[i];
+                (*joyStickButtons_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
+                (*joyStickButtons_[iDev])[i].groupName_ = "JoyStickButtons_" + deviceName;
             }
             // joy stick axes
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
             {
-                joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2];
+                (*joyStickAxes_[iDev])[i].name_ = JoyStickAxisCode::ByString[i / 2];
                 if (i & 1)
-                    joyStickAxes_[iDev][i].name_ += "Pos";
+                    (*joyStickAxes_[iDev])[i].name_ += "Pos";
                 else
-                    joyStickAxes_[iDev][i].name_ += "Neg";
-                joyStickAxes_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
-                joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName;
+                    (*joyStickAxes_[iDev])[i].name_ += "Neg";
+                (*joyStickAxes_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
+                (*joyStickAxes_[iDev])[i].groupName_ = "JoyStickAxes_" + deviceName;
             }
         }
@@ -226,9 +228,9 @@
         {
             for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
-                allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
+                allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "." + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
             {
-                allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
-                allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
+                allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "." + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
+                allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i]));
             }
         }
@@ -303,6 +305,6 @@
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
             {
-                joyStickAxes_[iDev][i].absVal_ = 0.0f;
-                joyStickAxes_[iDev][i].relVal_ = 0.0f;
+                (*joyStickAxes_[iDev])[i].absVal_ = 0.0f;
+                (*joyStickAxes_[iDev])[i].relVal_ = 0.0f;
             }
         }
@@ -366,5 +368,5 @@
         for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
         {
-            tickHalfAxis(joyStickAxes_[joyStick][i]);
+            tickHalfAxis((*joyStickAxes_[joyStick])[i]);
         }
     }
@@ -481,5 +483,5 @@
     {
         int i = axisID * 2;
-        JoyStickAxisVector& axis = joyStickAxes_[device];
+        JoyStickAxisVector& axis = *joyStickAxes_[device];
         if (value < 0)
         {
Index: code/trunk/src/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/core/input/KeyBinder.h	(revision 3370)
+++ code/trunk/src/core/input/KeyBinder.h	(revision 5695)
@@ -41,4 +41,5 @@
 #include <string>
 #include <vector>
+#include <boost/shared_ptr.hpp>
 
 #include "InputHandler.h"
@@ -115,5 +116,5 @@
         };
         //! Actual key bindings for joy stick buttons
-        std::vector<JoyStickButtonVector> joyStickButtons_;
+        std::vector<shared_ptr<JoyStickButtonVector> > joyStickButtons_;
         //! Helper class to use something like std:vector<HalfAxis[48]>
         struct JoyStickAxisVector
@@ -123,5 +124,5 @@
         };
         //! Actual key bindings for joy stick axes (and sliders)
-        std::vector<JoyStickAxisVector> joyStickAxes_;
+        std::vector<shared_ptr<JoyStickAxisVector> > joyStickAxes_;
 
         //! Pointer map with all Buttons, including half axes
@@ -191,11 +192,11 @@
 
     inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
-    { joyStickButtons_[device][button].execute(KeybindMode::OnPress); }
+    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress); }
 
     inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
-    { joyStickButtons_[device][button].execute(KeybindMode::OnRelease); }
+    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease); }
 
     inline void KeyBinder::buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button)
-    { joyStickButtons_[device][button].execute(KeybindMode::OnHold); }
+    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnHold); }
 
     inline void KeyBinder::allDevicesUpdated(float dt)
Index: code/trunk/src/core/input/KeyDetector.cc
===================================================================
--- code/trunk/src/core/input/KeyDetector.cc	(revision 3370)
+++ code/trunk/src/core/input/KeyDetector.cc	(revision 5695)
@@ -70,5 +70,6 @@
     {
         KeyBinder::JoyStickQuantityChanged(joyStickList);
-        setCallbackCommand(callbackCommand_);
+        if (!callbackCommand_.empty())
+            setCallbackCommand(callbackCommand_);
     }
 }
