Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

inputserver.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: inputserver.h,v 1.9 2004/12/31 11:03:10 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #ifndef KEROSIN_INPUTSERVER_H
00023 #define KEROSIN_INPUTSERVER_H
00024 
00025 #include <zeitgeist/node.h>
00026 
00027 namespace kerosin
00028 {
00029 
00030 class InputSystem;
00031 class InputDevice;
00032 class ScanCodeMap;
00033 
00034 /*      \class InputServer
00035         InputServer
00036 
00037         The InputServer of Kerosin is basically the next generation of
00038         the inputserver which has been developed for AGSPT. It tries
00039         to do a few more things more cleanly than the InputServer in
00040         the AGSPT frame- work.
00041 
00042         One major feature is that the input server does not directly
00043         deal with the API used to handle inputs. This is now done via
00044         an input system.  This enables a pluggable solution for the
00045         inputsystem and its devices.
00046 
00047         Another novel approach is that the binding is done directly
00048         via the input server and not through the individual devices.
00049 
00050         NOTE:
00051 
00052         HISTORY:
00053                 21.08.02 - MK
00054                         - Initial version
00055 
00056         TODO:
00057 
00058         TOFIX:
00059 */
00060 class InputServer : public zeitgeist::Node
00061 {
00062     //
00063     // Types
00064     //
00065 private:
00066     typedef std::list<InputDevice*> TDeviceList;
00067 
00068 public:
00069     typedef int TInputCode;
00070 
00071     enum EModifiers
00072     {
00073         eNone   = 0x0000,
00074         eLShift = 0x0001,
00075         eRShift = 0x0002,
00076         eShift  = 0x0003,       // eLShift|eRShift
00077         eLCtrl  = 0x0040,
00078         eRCtrl  = 0x0080,
00079         eCtrl   = 0x00c0,       // eLCtrl|eRCtrl
00080         eLAlt   = 0x0100,
00081         eRAlt   = 0x0200,
00082         eAlt    = 0x0300,       // eLAlt|eRAlt
00083         eNum    = 0x1000,
00084         eCaps   = 0x2000,
00085     };
00086 
00088     enum EType
00089     {
00090         eUnknown,       // default value, indicating a not initialized
00091                         // input event
00092         eButton,        // all buttons of a keyboard and mouse buttons
00093         eAxis,          // two mouse axis, the mouse wheel and the
00094                         // time axis
00095         eUser           // a user specified input event (used by the
00096                         // window server)
00097     };
00098 
00102     struct Input
00103     {
00104     public:
00106         EType           type;
00107 
00109         TInputCode      code;
00110 
00114         int id;
00115 
00117         union
00118         {
00122             long l;
00123 
00125             float  f;
00126         } data;
00127 
00128     public:
00130         Input(EType t = eUnknown, TInputCode c=0, int i=-1)
00131             : type(t),code(c),id(i) {}
00132 
00134         bool KeyPress() const { return (data.l == 1); }
00135 
00137         bool KeyRelease() const { return (data.l == 0); }
00138     };
00139 
00143     enum EBindEvent
00144     {
00145         eKeyUp          = 1,    // the key-release event is bound
00146         eKeyDown        = 2,    // the key-pressed event is bound
00147         eKeyUpDown      = 3,    // both events are bound (==
00148                                 // IDB_KEYUP|IDB_KEYDOWN)
00149     };
00150 
00155     struct Bind
00156     {
00157         int code;              // a value identifying the button or
00158                                // axis (see TInputCodes)
00159         int cmd;               // the associated user defined value
00160         unsigned int modifier; // a bitmask of modifiers (see
00161                                // EModifiers)
00162         EBindEvent event;      // the used filter (see enum EBind)
00163     };
00164 
00165     typedef std::list<Bind> TBindList;
00166 
00167 #ifdef HAVE_HASH_MAP
00168     typedef std::hash_map<int, TBindList>   TBindMap;
00169 #else
00170     typedef std::map<int, TBindList>        TBindMap;
00171 #endif
00172 
00173     //
00174     // Methods
00175     //
00176 public:
00177     InputServer();
00178     ~InputServer();
00179 
00181     bool Init(const std::string &inputSysName);
00182 
00184     bool CreateDevice(const std::string &deviceName);
00185 
00189     void Reset();
00190 
00191     bool GetInput(Input &input, bool raw = false);
00192 
00205     bool BindCommand(const std::string &desc, int cmd);
00206 
00210     void SetScanCodeMapping(const std::string &name);
00211 
00213     void AddCode(TInputCode ic, const std::string &name,
00214                  char noMod, char shiftMod, char altMod);
00215 
00219     bool TranslateCode(TInputCode code, unsigned long state, char &ch) const;
00220 
00222     void Invoke(int cmd);
00223 
00224 private:
00225     bool ParseBindDescription(Bind &bind, const std::string &desc);
00226     int ParseModifier(const std::string &modifier) const;
00227     boost::shared_ptr<InputSystem> GetInputSystem();
00228 
00229     //
00230     // Members
00231     //
00232 public:
00233     static const TInputCode IC_1;
00234     static const TInputCode IC_2;
00235     static const TInputCode IC_3;
00236     static const TInputCode IC_4;
00237     static const TInputCode IC_5;
00238     static const TInputCode IC_6;
00239     static const TInputCode IC_7;
00240     static const TInputCode IC_8;
00241     static const TInputCode IC_9;
00242     static const TInputCode IC_0;
00243     // function keys
00244     static const TInputCode IC_F1;
00245     static const TInputCode IC_F2;
00246     static const TInputCode IC_F3;
00247     static const TInputCode IC_F4;
00248     static const TInputCode IC_F5;
00249     static const TInputCode IC_F6;
00250     static const TInputCode IC_F7;
00251     static const TInputCode IC_F8;
00252     static const TInputCode IC_F9;
00253     static const TInputCode IC_F10;
00254     static const TInputCode IC_F11;
00255     static const TInputCode IC_F12;
00256     // alphabet
00257     static const TInputCode IC_A;
00258     static const TInputCode IC_B;
00259     static const TInputCode IC_C;
00260     static const TInputCode IC_D;
00261     static const TInputCode IC_E;
00262     static const TInputCode IC_F;
00263     static const TInputCode IC_G;
00264     static const TInputCode IC_H;
00265     static const TInputCode IC_I;
00266     static const TInputCode IC_J;
00267     static const TInputCode IC_K;
00268     static const TInputCode IC_L;
00269     static const TInputCode IC_M;
00270     static const TInputCode IC_N;
00271     static const TInputCode IC_O;
00272     static const TInputCode IC_P;
00273     static const TInputCode IC_Q;
00274     static const TInputCode IC_R;
00275     static const TInputCode IC_S;
00276     static const TInputCode IC_T;
00277     static const TInputCode IC_U;
00278     static const TInputCode IC_V;
00279     static const TInputCode IC_W;
00280     static const TInputCode IC_X;
00281     static const TInputCode IC_Y;
00282     static const TInputCode IC_Z;
00283     // keypad
00284     static const TInputCode IC_KP0;
00285     static const TInputCode IC_KP1;
00286     static const TInputCode IC_KP2;
00287     static const TInputCode IC_KP3;
00288     static const TInputCode IC_KP4;
00289     static const TInputCode IC_KP5;
00290     static const TInputCode IC_KP6;
00291     static const TInputCode IC_KP7;
00292     static const TInputCode IC_KP8;
00293     static const TInputCode IC_KP9;
00294     static const TInputCode IC_KP_DECIMAL;
00295     static const TInputCode IC_KP_DIVIDE;
00296     static const TInputCode IC_KP_MULTIPLY;
00297     static const TInputCode IC_KP_MINUS;
00298     static const TInputCode IC_KP_PLUS;
00299     static const TInputCode IC_KP_ENTER;
00300     // arrows + home/end pad
00301     static const TInputCode IC_UP;
00302     static const TInputCode IC_DOWN;
00303     static const TInputCode IC_LEFT;
00304     static const TInputCode IC_RIGHT;
00305     static const TInputCode IC_INSERT;
00306     static const TInputCode IC_DELETE;
00307     static const TInputCode IC_HOME;
00308     static const TInputCode IC_END;
00309     static const TInputCode IC_PAGEUP;
00310     static const TInputCode IC_PAGEDOWN;
00311     // key state modifier keys
00312     static const TInputCode IC_NUMLOCK;
00313     static const TInputCode IC_CAPSLOCK;
00314     static const TInputCode IC_SCROLLOCK;
00315     static const TInputCode IC_LSHIFT;
00316     static const TInputCode IC_RSHIFT;
00317     static const TInputCode IC_LCTRL;
00318     static const TInputCode IC_RCTRL;
00319     static const TInputCode IC_LALT;
00320     static const TInputCode IC_RALT;
00321     static const TInputCode IC_LSUPER;      // Left "Windows" key
00322     static const TInputCode IC_RSUPER;      // Right "Windows" key
00323     // other keys (cursor control, punctuation)
00324     static const TInputCode IC_ESCAPE;
00325     static const TInputCode IC_PRINT;
00326     static const TInputCode IC_PAUSE;
00327     static const TInputCode IC_GRAVE;
00328     static const TInputCode IC_MINUS;
00329     static const TInputCode IC_EQUALS;
00330     static const TInputCode IC_BACKSLASH;
00331     static const TInputCode IC_BACKSPACE;
00332 
00333     static const TInputCode IC_TAB;
00334     static const TInputCode IC_LBRACKET;
00335     static const TInputCode IC_RBRACKET;
00336     static const TInputCode IC_RETURN;
00337 
00338     static const TInputCode IC_SEMICOLON;
00339     static const TInputCode IC_APOSTROPHE;
00340 
00341     static const TInputCode IC_OEM_102;     // German <>|
00342     static const TInputCode IC_COMMA;
00343     static const TInputCode IC_PERIOD;
00344     static const TInputCode IC_SLASH;
00345 
00346     static const TInputCode IC_SPACE;
00347 
00348     // mouse buttons
00349     static const TInputCode IC_MOUSE_LEFT;   // left
00350     static const TInputCode IC_MOUSE_RIGHT;  // right
00351     static const TInputCode IC_MOUSE_MIDDLE; // middle
00352 
00353     //mouse axis
00354     static const TInputCode IC_AXISX;
00355     static const TInputCode IC_AXISY;
00356     static const TInputCode IC_AXISZ;
00357 
00358     // timer
00359     static const TInputCode IC_AXIST;
00360 
00361     // this is the up-to-date state of the modifier keys
00362     unsigned int    mModifierState;
00363 
00364 private:
00366     std::string mScanCodeScript;
00367 
00369     boost::shared_ptr<ScanCodeMap>  mScanCodeMap;
00370 
00372     TBindMap mBindings;
00373 };
00374 
00375 DECLARE_CLASS(InputServer);
00376 
00377 } // kerosin
00378 
00379 #endif //KEROSIN_INPUTSERVER_H
00380 

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4