00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class InputServer : public zeitgeist::Node
00061 {
00062
00063
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,
00077 eLCtrl = 0x0040,
00078 eRCtrl = 0x0080,
00079 eCtrl = 0x00c0,
00080 eLAlt = 0x0100,
00081 eRAlt = 0x0200,
00082 eAlt = 0x0300,
00083 eNum = 0x1000,
00084 eCaps = 0x2000,
00085 };
00086
00088 enum EType
00089 {
00090 eUnknown,
00091
00092 eButton,
00093 eAxis,
00094
00095 eUser
00096
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,
00146 eKeyDown = 2,
00147 eKeyUpDown = 3,
00148
00149 };
00150
00155 struct Bind
00156 {
00157 int code;
00158
00159 int cmd;
00160 unsigned int modifier;
00161
00162 EBindEvent event;
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
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
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
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
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
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
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
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;
00322 static const TInputCode IC_RSUPER;
00323
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;
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
00349 static const TInputCode IC_MOUSE_LEFT;
00350 static const TInputCode IC_MOUSE_RIGHT;
00351 static const TInputCode IC_MOUSE_MIDDLE;
00352
00353
00354 static const TInputCode IC_AXISX;
00355 static const TInputCode IC_AXISY;
00356 static const TInputCode IC_AXISZ;
00357
00358
00359 static const TInputCode IC_AXIST;
00360
00361
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 }
00378
00379 #endif //KEROSIN_INPUTSERVER_H
00380