Index: code/branches/merge/src/core/InputManager.cc
===================================================================
--- code/branches/merge/src/core/InputManager.cc	(revision 1268)
+++ code/branches/merge/src/core/InputManager.cc	(revision 1272)
@@ -30,5 +30,5 @@
   @file
   @brief Implementation of the InputManager that captures all the input from OIS
-         and redirects it to handlers if necessary.
+         and redirects it to handlers.
  */
 
@@ -52,12 +52,9 @@
   InputManager::InputManager() :
       inputSystem_(0), keyboard_(0), mouse_(0),
-      state_(IS_UNINIT), stateRequest_(IS_UNINIT)
+      joySticksSize_(0),
+      state_(IS_UNINIT), stateRequest_(IS_UNINIT),
+      keyboardModifiers_(0)
   {
     RegisterObject(InputManager);
-
-    this->joySticks_.reserve(5);
-    //this->activeJoyStickHandlers_.reserve(10);
-    this->activeKeyHandlers_.reserve(10);
-    this->activeMouseHandlers_.reserve(10);
   }
 
@@ -87,6 +84,6 @@
     @param windowHeight The height of the render window
   */
-  bool InputManager::_initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
-        const bool createKeyboard, const bool createMouse, const bool createJoySticks)
+  bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight,
+        bool createKeyboard, bool createMouse, bool createJoySticks)
   {
     if (state_ == IS_UNINIT)
@@ -146,4 +143,5 @@
     addKeyHandler(binder, "keybinder");
     addMouseHandler(binder, "keybinder");
+    addJoyStickHandler(binder, "keybinder");
 
     // Read all the key bindings and assign them
@@ -235,5 +233,5 @@
   bool InputManager::_initialiseJoySticks()
   {
-    if (joySticks_.size() > 0)
+    if (joySticksSize_ > 0)
     {
       CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl;
@@ -266,4 +264,7 @@
       return false;
     }
+    joySticksSize_ = joySticks_.size();
+    activeJoyStickHandlers_.resize(joySticksSize_);
+    joyStickButtonsDown_.resize(joySticksSize_);
     return success;
   }
@@ -337,12 +338,13 @@
   void InputManager::_destroyJoySticks()
   {
-    if (joySticks_.size() > 0)
+    if (joySticksSize_ > 0)
     {
       // note: inputSystem_ can never be 0, or else the code is mistaken
-      for (unsigned int i = 0; i < joySticks_.size(); i++)
+      for (unsigned int i = 0; i < joySticksSize_; i++)
         if (joySticks_[i] != 0)
           inputSystem_->destroyInputObject(joySticks_[i]);
 
       joySticks_.clear();
+      joySticksSize_ = 0;
       activeJoyStickHandlers_.clear();
       joyStickButtonsDown_.clear();
@@ -373,5 +375,6 @@
         activeKeyHandlers_.clear();
         activeMouseHandlers_.clear();
-        activeJoyStickHandlers_.clear();
+        for (unsigned int i = 0; i < joySticksSize_; i++)
+          activeJoyStickHandlers_[i].clear();
 
         switch (stateRequest_)
@@ -383,7 +386,6 @@
           activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
           activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
-          for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();
-                it != joySticks_.end(); it++)
-            activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]);
+          for (unsigned int i = 0; i < joySticksSize_; i++)
+            activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
           break;
 
@@ -394,7 +396,7 @@
         case IS_CONSOLE:
           activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
-          for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();
-                it != joySticks_.end(); it++)
-            activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]);
+          activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
+          for (unsigned int i = 0; i < joySticksSize_; i++)
+            activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
 
           activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
@@ -413,39 +415,25 @@
     if (keyboard_)
       keyboard_->capture();
+    for (unsigned  int i = 0; i < joySticksSize_; i++)
+      joySticks_[i]->capture();
 
 
     // call all the handlers for the held key events
-    for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin();
-          itKey != keysDown_.end(); itKey++)
-    {
-      OIS::KeyEvent keyArg(keyboard_, *itKey, 0);
-      for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
-        activeKeyHandlers_[i]->keyHeld(keyArg);
-    }
+    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
+      for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
+        activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
 
     // call all the handlers for the held mouse button events
-    for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin();
-          itMouseButton != mouseButtonsDown_.end(); itMouseButton++)
-    {
-      OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState());
-      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
-        activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton);
-    }
+    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
+      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
+        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]);
 
     // call all the handlers for the held joy stick button events
-    for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin();
-          itJoyStick != joyStickButtonsDown_.end(); itJoyStick++)
-    {
-      OIS::JoyStick* joyStick = (*itJoyStick).first;
-      for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin();
-            itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++)
-      {
-        OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState());
-        for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-          activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton);
-      }
-    }
-  }
-
+    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
+      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
+        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(
+              JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]);
+  }
 
   // ###### Key Events ######
@@ -458,16 +446,20 @@
   {
     // check whether the key already is in the list (can happen when focus was lost)
-    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
-    {
-      if (*it == e.key)
-      {
-        keysDown_.erase(it);
-        break;
-      }
-    }
-    keysDown_.push_back(e.key);
+    unsigned int iKey = 0;
+    while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::Enum)e.key)
+      iKey++;
+    if (iKey == keysDown_.size())
+      keysDown_.push_back(Key(e));
+
+    // update modifiers
+    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
+      keyboardModifiers_ |= KeyboardModifier::Alt;   // alt key
+    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
+      keyboardModifiers_ |= KeyboardModifier::Ctrl;  // ctrl key
+    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
+      keyboardModifiers_ |= KeyboardModifier::Shift; // shift key
 
     for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
-      activeKeyHandlers_[i]->keyPressed(e);
+      activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_));
 
     return true;
@@ -481,15 +473,23 @@
   {
     // remove the key from the keysDown_ list
-    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
-    {
-      if (*it == e.key)
-      {
-        keysDown_.erase(it);
+    for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
+    {
+      if (keysDown_[iKey].key == (KeyCode::Enum)e.key)
+      {
+        keysDown_.erase(keysDown_.begin() + iKey);
         break;
       }
     }
 
+    // update modifiers
+    if(e.key == OIS::KC_RMENU    || e.key == OIS::KC_LMENU)
+      keyboardModifiers_ &= ~KeyboardModifier::Alt;   // alt key
+    if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL)
+      keyboardModifiers_ &= ~KeyboardModifier::Ctrl;  // ctrl key
+    if(e.key == OIS::KC_RSHIFT   || e.key == OIS::KC_LSHIFT)
+      keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key
+
     for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
-      activeKeyHandlers_[i]->keyReleased(e);
+      activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_));
 
     return true;
@@ -505,6 +505,17 @@
   bool InputManager::mouseMoved(const OIS::MouseEvent &e)
   {
-    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
-      activeMouseHandlers_[i]->mouseMoved(e);
+    // check for actual moved event
+    if (e.state.X.rel != 0 || e.state.Y.rel != 0)
+    {
+      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
+        activeMouseHandlers_[i]->mouseMoved(e.state);
+    }
+
+    // check for mouse scrolled event
+    if (e.state.Z.rel != 0)
+    {
+      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
+        activeMouseHandlers_[i]->mouseScrolled(e.state);
+    }
 
     return true;
@@ -519,16 +530,12 @@
   {
     // check whether the button already is in the list (can happen when focus was lost)
-    for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
-    {
-      if (*it == id)
-      {
-        mouseButtonsDown_.erase(it);
-        break;
-      }
-    }
-    mouseButtonsDown_.push_back(id);
+    unsigned int iButton = 0;
+    while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButton::Enum)id)
+      iButton++;
+    if (iButton == mouseButtonsDown_.size())
+      mouseButtonsDown_.push_back((MouseButton::Enum)id);
 
     for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
-      activeMouseHandlers_[i]->mousePressed(e, id);
+      activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id);
 
     return true;
@@ -543,9 +550,9 @@
   {
     // remove the button from the keysDown_ list
-    for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
-    {
-      if (*it == id)
-      {
-        mouseButtonsDown_.erase(it);
+    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
+    {
+      if (mouseButtonsDown_[iButton] == (MouseButton::Enum)id)
+      {
+        mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton);
         break;
       }
@@ -553,5 +560,5 @@
 
     for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
-      activeMouseHandlers_[i]->mouseReleased(e, id);
+      activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id);
 
     return true;
@@ -563,77 +570,101 @@
   bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
   {
+    // use the device to identify which one called the method
     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
+    unsigned int iJoyStick = 0;
+    while (joySticks_[iJoyStick] != joyStick)
+      iJoyStick++;
 
     // check whether the button already is in the list (can happen when focus was lost)
-    std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
-    for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
-    {
-      if (*it == button)
-      {
-        buttonsDownList.erase(it);
+    std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
+    unsigned int iButton = 0;
+    while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
+      iButton++;
+    if (iButton == buttonsDown.size())
+      buttonsDown.push_back(button);
+
+    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button);
+
+    return true;
+  }
+
+  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
+  {
+    // use the device to identify which one called the method
+    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
+    unsigned int iJoyStick = 0;
+    while (joySticks_[iJoyStick] != joyStick)
+      iJoyStick++;
+
+    // remove the button from the joyStickButtonsDown_ list
+    std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
+    for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
+    {
+      if (buttonsDown[iButton] == button)
+      {
+        buttonsDown.erase(buttonsDown.begin() + iButton);
         break;
       }
     }
-    joyStickButtonsDown_[joyStick].push_back(button);
-
-    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-      activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button);
-
-    return true;
-  }
-
-  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
-  {
+
+    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button);
+
+    return true;
+  }
+
+  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
+  {
+    // use the device to identify which one called the method
     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
-
-    // remove the button from the joyStickButtonsDown_ list
-    std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
-    for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
-    {
-      if (*it == button)
-      {
-        buttonsDownList.erase(it);
-        break;
-      }
-    }
-
-    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-      activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button);
-
-    return true;
-  }
-
-  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
-  {
+    unsigned int iJoyStick = 0;
+    while (joySticks_[iJoyStick] != joyStick)
+      iJoyStick++;
+
+    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis);
+
+    return true;
+  }
+
+  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
+  {
+    // use the device to identify which one called the method
     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
-    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-      activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis);
-
-    return true;
-  }
-
-  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
-  {
+    unsigned int iJoyStick = 0;
+    while (joySticks_[iJoyStick] != joyStick)
+      iJoyStick++;
+
+    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id);
+
+    return true;
+  }
+
+  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
+  {
+    // use the device to identify which one called the method
     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
-    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-      activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id);
-
-    return true;
-  }
-
-  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
-  {
+    unsigned int iJoyStick = 0;
+    while (joySticks_[iJoyStick] != joyStick)
+      iJoyStick++;
+
+    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id);
+
+    return true;
+  }
+
+  bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
+  {
+    // use the device to identify which one called the method
     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
-    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-      activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id);
-
-    return true;
-  }
-
-  bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
-  {
-    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
-    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
-      activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id);
+    unsigned int iJoyStick = 0;
+    while (joySticks_[iJoyStick] != joyStick)
+      iJoyStick++;
+
+    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
+      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id);
 
     return true;
@@ -646,6 +677,6 @@
   // ################################
 
-  bool InputManager::initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
-    const bool createKeyboard, const bool createMouse, const bool createJoySticks)
+  bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
+    bool createKeyboard, bool createMouse, bool createJoySticks)
   {
     return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight,
@@ -686,5 +717,37 @@
   int InputManager::numberOfJoySticks()
   {
-    return _getSingleton().joySticks_.size();
+    return _getSingleton().joySticksSize_;
+  }
+
+  bool InputManager::isKeyDown(KeyCode::Enum key)
+  {
+    if (_getSingleton().keyboard_)
+      return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key);
+    else
+      return false;
+  }
+
+  bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
+  {
+    if (_getSingleton().keyboard_)
+      return isModifierDown(modifier);
+    else
+      return false;
+  }
+
+  const MouseState InputManager::getMouseState()
+  {
+    if (_getSingleton().mouse_)
+      return _getSingleton().mouse_->getMouseState();
+    else
+      return MouseState();
+  }
+
+  const JoyStickState InputManager::getJoyStickState(unsigned int ID)
+  {
+    if (ID < _getSingleton().joySticksSize_)
+      return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID);
+    else
+      return JoyStickState();
   }
 
@@ -1062,5 +1125,5 @@
     @return False if name or id was not found, true otherwise.
   */
-  bool InputManager::enableJoyStickHandler(const std::string& name, const int ID)
+  bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID)
   {
     // get handler pointer from the map with all stored handlers
@@ -1070,11 +1133,10 @@
 
     // check for existence of the ID
-    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
-      return false;
-    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
+    if (ID >= _getSingleton().joySticksSize_)
+      return false;
 
     // see whether the handler already is in the list
-    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
-          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
+    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
+          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
     {
       if ((*it) == (*handlerIt).second)
@@ -1084,5 +1146,5 @@
       }
     }
-    _getSingleton().activeJoyStickHandlers_[joyStick].push_back((*handlerIt).second);
+    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
     _getSingleton().stateRequest_ = IS_CUSTOM;
     return true;
@@ -1094,5 +1156,5 @@
     @return False if name or id was not found, true otherwise.
   */
-  bool InputManager::disableJoyStickHandler(const std::string &name, int ID)
+  bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID)
   {
     // get handler pointer from the map with all stored handlers
@@ -1102,15 +1164,14 @@
 
     // check for existence of the ID
-    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
-      return false;
-    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
+    if (ID >= _getSingleton().joySticksSize_)
+      return false;
 
     // look for the handler in the list
-    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
-          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
+    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
+          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
     {
       if ((*it) == (*handlerIt).second)
       {
-        _getSingleton().activeJoyStickHandlers_[joyStick].erase(it);
+        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
         _getSingleton().stateRequest_ = IS_CUSTOM;
         return true;
@@ -1125,5 +1186,5 @@
     @return False if key handler is not active or doesn't exist, true otherwise.
   */
-  bool InputManager::isJoyStickHandlerActive(const std::string& name, const int ID)
+  bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID)
   {
     // get handler pointer from the map with all stored handlers
@@ -1133,11 +1194,10 @@
 
     // check for existence of the ID
-    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
-      return false;
-    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
+    if (ID >= _getSingleton().joySticksSize_)
+      return false;
 
     // see whether the handler already is in the list
-    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
-          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
+    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin();
+          it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++)
     {
       if ((*it) == (*handlerIt).second)
