Index: code/trunk/src/core/InputManager.h
===================================================================
--- code/trunk/src/core/InputManager.h	(revision 1349)
+++ code/trunk/src/core/InputManager.h	(revision 1502)
@@ -65,4 +65,22 @@
   public:
     IntVector2 sliderStates[4];
+  };
+
+  /**
+  * Struct for storing a custom input state
+  */
+  struct StoredState
+  {
+    std::vector<KeyHandler*>                    activeKeyHandlers_;
+    std::vector<MouseHandler*>                  activeMouseHandlers_;
+    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
+    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
+  };
+
+  struct JoyStickCalibration
+  {
+    int zeroStates[24];
+    float positiveCoeff[24];
+    float negativeCoeff[24];
   };
 
@@ -80,11 +98,18 @@
     enum InputState
     {
-      IS_UNINIT,  //!< InputManager has not yet been initialised.
-      IS_NONE,    //!< Input is discarded.
-      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
-      IS_GUI,     //!< All OIS input events are passed to CEGUI.
-      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
-      IS_CUSTOM   //!< Any possible configuration.
+      IS_UNINIT,    //!< InputManager has not yet been initialised.
+      IS_NONE,      //!< Input is discarded.
+      IS_NORMAL,    //!< Normal play state. Key and button bindings are active.
+      IS_GUI,       //!< All OIS input events are passed to CEGUI.
+      IS_CONSOLE,   //!< Keyboard input is redirected to the InputBuffer.
+      IS_DETECT,    //!< All the input additionally goes to the KeyDetector
+      IS_NODETECT,  //!< remove KeyDetector
+      IS_NOCALIBRATE,
+      IS_CALIBRATE,
+      IS_CUSTOM     //!< Any possible configuration.
     };
+
+  public: // member functions
+    void setConfigValues();
 
   public: // static functions
@@ -103,6 +128,6 @@
     static void destroyJoySticks();
 
-    static bool isModifierDown(KeyboardModifier::Enum modifier);
-    static bool isKeyDown(KeyCode::Enum key);
+    //static bool isModifierDown(KeyboardModifier::Enum modifier);
+    //static bool isKeyDown(KeyCode::Enum key);
     //static const MouseState getMouseState();
     //static const JoyStickState getJoyStickState(unsigned int ID);
@@ -112,4 +137,9 @@
     static void setInputState(const InputState state);
     static InputState getInputState();
+
+    static void storeKeyStroke(const std::string& name);
+    static void keyBind(const std::string& command);
+
+    static void calibrate();
 
     static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
@@ -152,4 +182,12 @@
 
     void _updateTickables();
+
+    void _saveState();
+    void _restoreState();
+
+    void _completeCalibration();
+
+    void _fireAxis(unsigned int iJoyStick, int axis, int value);
+    unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
 
     void tick(float dt);
@@ -172,13 +210,27 @@
 
   private: // variables
-    OIS::InputManager*                          inputSystem_; //!< OIS input manager
-    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
-    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
-    std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
+    OIS::InputManager*                          inputSystem_;     //!< OIS input manager
+    OIS::Keyboard*                              keyboard_;        //!< OIS mouse
+    OIS::Mouse*                                 mouse_;           //!< OIS keyboard
+    std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
     unsigned int                                joySticksSize_;
+
+    KeyBinder*                                  keyBinder_;       //!< KeyBinder instance
+    KeyDetector*                                keyDetector_;     //!< KeyDetector instance
+    InputBuffer*                                buffer_;          //!< InputBuffer instance
+    CalibratorCallback*                         calibratorCallback_;
 
     InputState state_;
     InputState stateRequest_;
+    InputState savedState_;
     unsigned int keyboardModifiers_;
+    StoredState savedHandlers_;
+
+    // joystick calibration
+    //std::vector<int> marginalsMaxConfig_;
+    //std::vector<int> marginalsMinConfig_;
+    int marginalsMax_[24];
+    int marginalsMin_[24];
+    bool bCalibrated_;
 
     //! Keeps track of the joy stick POV states
@@ -186,4 +238,5 @@
     //! Keeps track of the possibly two slider axes
     std::vector<SliderStates>                   sliderStates_;
+    std::vector<JoyStickCalibration>            joySticksCalibration_;
 
     std::map<std::string, KeyHandler*>          keyHandlers_;
@@ -194,5 +247,5 @@
     std::vector<MouseHandler*>                  activeMouseHandlers_;
     std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
-    std::vector<InputTickable*>                 activeHandlers_;
+    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
 
     std::vector<Key>                            keysDown_;
@@ -200,4 +253,5 @@
     std::vector<std::vector<int> >              joyStickButtonsDown_;
 
+    static std::string                          bindingCommmandString_s;
   };
 
