00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "inputserver.h"
00023 #include "inputsystem.h"
00024 #include "inputdevice.h"
00025 #include "scancodemap.h"
00026 #include <zeitgeist/logserver/logserver.h>
00027 #include <zeitgeist/scriptserver/scriptserver.h>
00028 #include <sstream>
00029
00030 using namespace boost;
00031 using namespace kerosin;
00032 using namespace std;
00033 using namespace zeitgeist;
00034
00035 const InputServer::TInputCode InputServer::IC_1 = 0x02;
00036 const InputServer::TInputCode InputServer::IC_2 = 0x03;
00037 const InputServer::TInputCode InputServer::IC_3 = 0x04;
00038 const InputServer::TInputCode InputServer::IC_4 = 0x05;
00039 const InputServer::TInputCode InputServer::IC_5 = 0x06;
00040 const InputServer::TInputCode InputServer::IC_6 = 0x07;
00041 const InputServer::TInputCode InputServer::IC_7 = 0x08;
00042 const InputServer::TInputCode InputServer::IC_8 = 0x09;
00043 const InputServer::TInputCode InputServer::IC_9 = 0x0a;
00044 const InputServer::TInputCode InputServer::IC_0 = 0x0b;
00045
00046
00047 const InputServer::TInputCode InputServer::IC_F1 = 0x3b;
00048 const InputServer::TInputCode InputServer::IC_F2 = 0x3c;
00049 const InputServer::TInputCode InputServer::IC_F3 = 0x3d;
00050 const InputServer::TInputCode InputServer::IC_F4 = 0x3e;
00051 const InputServer::TInputCode InputServer::IC_F5 = 0x3f;
00052 const InputServer::TInputCode InputServer::IC_F6 = 0x40;
00053 const InputServer::TInputCode InputServer::IC_F7 = 0x41;
00054 const InputServer::TInputCode InputServer::IC_F8 = 0x42;
00055 const InputServer::TInputCode InputServer::IC_F9 = 0x43;
00056 const InputServer::TInputCode InputServer::IC_F10 = 0x44;
00057 const InputServer::TInputCode InputServer::IC_F11 = 0x57;
00058 const InputServer::TInputCode InputServer::IC_F12 = 0x58;
00059
00060
00061 const InputServer::TInputCode InputServer::IC_A = 0x1e;
00062 const InputServer::TInputCode InputServer::IC_B = 0x30;
00063 const InputServer::TInputCode InputServer::IC_C = 0x2e;
00064 const InputServer::TInputCode InputServer::IC_D = 0x20;
00065 const InputServer::TInputCode InputServer::IC_E = 0x12;
00066 const InputServer::TInputCode InputServer::IC_F = 0x21;
00067 const InputServer::TInputCode InputServer::IC_G = 0x22;
00068 const InputServer::TInputCode InputServer::IC_H = 0x23;
00069 const InputServer::TInputCode InputServer::IC_I = 0x17;
00070 const InputServer::TInputCode InputServer::IC_J = 0x24;
00071 const InputServer::TInputCode InputServer::IC_K = 0x25;
00072 const InputServer::TInputCode InputServer::IC_L = 0x26;
00073 const InputServer::TInputCode InputServer::IC_M = 0x32;
00074 const InputServer::TInputCode InputServer::IC_N = 0x31;
00075 const InputServer::TInputCode InputServer::IC_O = 0x18;
00076 const InputServer::TInputCode InputServer::IC_P = 0x19;
00077 const InputServer::TInputCode InputServer::IC_Q = 0x10;
00078 const InputServer::TInputCode InputServer::IC_R = 0x13;
00079 const InputServer::TInputCode InputServer::IC_S = 0x1f;
00080 const InputServer::TInputCode InputServer::IC_T = 0x14;
00081 const InputServer::TInputCode InputServer::IC_U = 0x16;
00082 const InputServer::TInputCode InputServer::IC_V = 0x2f;
00083 const InputServer::TInputCode InputServer::IC_W = 0x11;
00084 const InputServer::TInputCode InputServer::IC_X = 0x2d;
00085 const InputServer::TInputCode InputServer::IC_Y = 0x15;
00086 const InputServer::TInputCode InputServer::IC_Z = 0x2c;
00087
00088
00089 const InputServer::TInputCode InputServer::IC_KP0 = 0x52;
00090 const InputServer::TInputCode InputServer::IC_KP1 = 0x4f;
00091 const InputServer::TInputCode InputServer::IC_KP2 = 0x50;
00092 const InputServer::TInputCode InputServer::IC_KP3 = 0x51;
00093 const InputServer::TInputCode InputServer::IC_KP4 = 0x4b;
00094 const InputServer::TInputCode InputServer::IC_KP5 = 0x4c;
00095 const InputServer::TInputCode InputServer::IC_KP6 = 0x4d;
00096 const InputServer::TInputCode InputServer::IC_KP7 = 0x47;
00097 const InputServer::TInputCode InputServer::IC_KP8 = 0x48;
00098 const InputServer::TInputCode InputServer::IC_KP9 = 0x49;
00099 const InputServer::TInputCode InputServer::IC_KP_DECIMAL = 0x53;
00100 const InputServer::TInputCode InputServer::IC_KP_DIVIDE = 0xb5;
00101 const InputServer::TInputCode InputServer::IC_KP_MULTIPLY = 0x37;
00102 const InputServer::TInputCode InputServer::IC_KP_MINUS = 0x4a;
00103 const InputServer::TInputCode InputServer::IC_KP_PLUS = 0x4e;
00104 const InputServer::TInputCode InputServer::IC_KP_ENTER = 0x8d;
00105
00106
00107 const InputServer::TInputCode InputServer::IC_UP = 0xc8;
00108 const InputServer::TInputCode InputServer::IC_DOWN = 0xd0;
00109 const InputServer::TInputCode InputServer::IC_LEFT = 0xcb;
00110 const InputServer::TInputCode InputServer::IC_RIGHT = 0xcd;
00111 const InputServer::TInputCode InputServer::IC_INSERT = 0xd2;
00112 const InputServer::TInputCode InputServer::IC_DELETE = 0xd3;
00113 const InputServer::TInputCode InputServer::IC_HOME = 0xc7;
00114 const InputServer::TInputCode InputServer::IC_END = 0xcf;
00115 const InputServer::TInputCode InputServer::IC_PAGEUP = 0xc9;
00116 const InputServer::TInputCode InputServer::IC_PAGEDOWN = 0xd1;
00117
00118
00119 const InputServer::TInputCode InputServer::IC_NUMLOCK = 0x45;
00120 const InputServer::TInputCode InputServer::IC_CAPSLOCK = 0x3a;
00121 const InputServer::TInputCode InputServer::IC_SCROLLOCK = 0x46;
00122 const InputServer::TInputCode InputServer::IC_LSHIFT = 0x2a;
00123 const InputServer::TInputCode InputServer::IC_RSHIFT = 0x36;
00124 const InputServer::TInputCode InputServer::IC_LCTRL = 0x1d;
00125 const InputServer::TInputCode InputServer::IC_RCTRL = 0x9d;
00126 const InputServer::TInputCode InputServer::IC_LALT = 0x38;
00127 const InputServer::TInputCode InputServer::IC_RALT = 0xb8;
00128 const InputServer::TInputCode InputServer::IC_LSUPER = 0xdb;
00129 const InputServer::TInputCode InputServer::IC_RSUPER = 0xdc;
00130
00131
00132 const InputServer::TInputCode InputServer::IC_ESCAPE = 0x01;
00133 const InputServer::TInputCode InputServer::IC_PRINT = 0xb7;
00134 const InputServer::TInputCode InputServer::IC_PAUSE = 0xc5;
00135 const InputServer::TInputCode InputServer::IC_GRAVE = 0x29;
00136 const InputServer::TInputCode InputServer::IC_MINUS = 0x0c;
00137 const InputServer::TInputCode InputServer::IC_EQUALS = 0x0d;
00138 const InputServer::TInputCode InputServer::IC_BACKSLASH = 0x2b;
00139 const InputServer::TInputCode InputServer::IC_BACKSPACE = 0x0e;
00140
00141 const InputServer::TInputCode InputServer::IC_TAB = 0x0f;
00142 const InputServer::TInputCode InputServer::IC_LBRACKET = 0x1a;
00143 const InputServer::TInputCode InputServer::IC_RBRACKET = 0x1b;
00144 const InputServer::TInputCode InputServer::IC_RETURN = 0x1c;
00145
00146 const InputServer::TInputCode InputServer::IC_SEMICOLON = 0x27;
00147 const InputServer::TInputCode InputServer::IC_APOSTROPHE= 0x28;
00148
00149 const InputServer::TInputCode InputServer::IC_OEM_102 = 0x56;
00150 const InputServer::TInputCode InputServer::IC_COMMA = 0x33;
00151 const InputServer::TInputCode InputServer::IC_PERIOD = 0x34;
00152 const InputServer::TInputCode InputServer::IC_SLASH = 0x35;
00153
00154 const InputServer::TInputCode InputServer::IC_SPACE = 0x39;
00155
00156
00157 const InputServer::TInputCode InputServer::IC_MOUSE_LEFT = 0x1000;
00158 const InputServer::TInputCode InputServer::IC_MOUSE_RIGHT = 0x1001;
00159 const InputServer::TInputCode InputServer::IC_MOUSE_MIDDLE = 0x1002;
00160
00161
00162 const InputServer::TInputCode InputServer::IC_AXISX = 0x2000;
00163 const InputServer::TInputCode InputServer::IC_AXISY = 0x2001;
00164 const InputServer::TInputCode InputServer::IC_AXISZ = 0x2002;
00165
00166
00167 const InputServer::TInputCode InputServer::IC_AXIST = 0x3000;
00168
00169 InputServer::InputServer() :
00170 Node(), mModifierState(eNone), mScanCodeMap(new ScanCodeMap())
00171 {
00172
00173 mScanCodeScript = "german.scan.rb";
00174 }
00175
00176 InputServer::~InputServer()
00177 {
00178 Reset();
00179 }
00180
00181 bool InputServer::Init(const std::string &inputSysName)
00182 {
00183 GetLog()->Normal() << "(InputServer) Init " << inputSysName << "\n";
00184 Reset();
00185
00186
00187 GetScript()->CreateVariable("Input.IC_1", IC_1);
00188 GetScript()->CreateVariable("Input.IC_2", IC_2);
00189 GetScript()->CreateVariable("Input.IC_3", IC_3);
00190 GetScript()->CreateVariable("Input.IC_4", IC_4);
00191 GetScript()->CreateVariable("Input.IC_5", IC_5);
00192 GetScript()->CreateVariable("Input.IC_6", IC_6);
00193 GetScript()->CreateVariable("Input.IC_7", IC_7);
00194 GetScript()->CreateVariable("Input.IC_8", IC_8);
00195 GetScript()->CreateVariable("Input.IC_9", IC_9);
00196 GetScript()->CreateVariable("Input.IC_0", IC_0);
00197
00198
00199 GetScript()->CreateVariable("Input.IC_F1", IC_F1);
00200 GetScript()->CreateVariable("Input.IC_F2", IC_F2);
00201 GetScript()->CreateVariable("Input.IC_F3", IC_F3);
00202 GetScript()->CreateVariable("Input.IC_F4", IC_F4);
00203 GetScript()->CreateVariable("Input.IC_F5", IC_F5);
00204 GetScript()->CreateVariable("Input.IC_F6", IC_F6);
00205 GetScript()->CreateVariable("Input.IC_F7", IC_F7);
00206 GetScript()->CreateVariable("Input.IC_F8", IC_F8);
00207 GetScript()->CreateVariable("Input.IC_F9", IC_F9);
00208 GetScript()->CreateVariable("Input.IC_F10", IC_F10);
00209 GetScript()->CreateVariable("Input.IC_F11", IC_F11);
00210 GetScript()->CreateVariable("Input.IC_F12", IC_F12);
00211
00212
00213 GetScript()->CreateVariable("Input.IC_A", IC_A);
00214 GetScript()->CreateVariable("Input.IC_B", IC_B);
00215 GetScript()->CreateVariable("Input.IC_C", IC_C);
00216 GetScript()->CreateVariable("Input.IC_D", IC_D);
00217 GetScript()->CreateVariable("Input.IC_E", IC_E);
00218 GetScript()->CreateVariable("Input.IC_F", IC_F);
00219 GetScript()->CreateVariable("Input.IC_G", IC_G);
00220 GetScript()->CreateVariable("Input.IC_H", IC_H);
00221 GetScript()->CreateVariable("Input.IC_I", IC_I);
00222 GetScript()->CreateVariable("Input.IC_J", IC_J);
00223 GetScript()->CreateVariable("Input.IC_K", IC_K);
00224 GetScript()->CreateVariable("Input.IC_L", IC_L);
00225 GetScript()->CreateVariable("Input.IC_M", IC_M);
00226 GetScript()->CreateVariable("Input.IC_N", IC_N);
00227 GetScript()->CreateVariable("Input.IC_O", IC_O);
00228 GetScript()->CreateVariable("Input.IC_P", IC_P);
00229 GetScript()->CreateVariable("Input.IC_Q", IC_Q);
00230 GetScript()->CreateVariable("Input.IC_R", IC_R);
00231 GetScript()->CreateVariable("Input.IC_S", IC_S);
00232 GetScript()->CreateVariable("Input.IC_T", IC_T);
00233 GetScript()->CreateVariable("Input.IC_U", IC_U);
00234 GetScript()->CreateVariable("Input.IC_V", IC_V);
00235 GetScript()->CreateVariable("Input.IC_W", IC_W);
00236 GetScript()->CreateVariable("Input.IC_X", IC_X);
00237 GetScript()->CreateVariable("Input.IC_Y", IC_Y);
00238 GetScript()->CreateVariable("Input.IC_Z", IC_Z);
00239
00240
00241 GetScript()->CreateVariable("Input.IC_KP0", IC_KP0);
00242 GetScript()->CreateVariable("Input.IC_KP1", IC_KP1);
00243 GetScript()->CreateVariable("Input.IC_KP2", IC_KP2);
00244 GetScript()->CreateVariable("Input.IC_KP3", IC_KP3);
00245 GetScript()->CreateVariable("Input.IC_KP4", IC_KP4);
00246 GetScript()->CreateVariable("Input.IC_KP5", IC_KP5);
00247 GetScript()->CreateVariable("Input.IC_KP6", IC_KP6);
00248 GetScript()->CreateVariable("Input.IC_KP7", IC_KP7);
00249 GetScript()->CreateVariable("Input.IC_KP8", IC_KP8);
00250 GetScript()->CreateVariable("Input.IC_KP9", IC_KP9);
00251 GetScript()->CreateVariable("Input.IC_KP_DECIMAL", IC_KP_DECIMAL);
00252 GetScript()->CreateVariable("Input.IC_KP_DIVIDE", IC_KP_DIVIDE);
00253 GetScript()->CreateVariable("Input.IC_KP_MULTIPLY", IC_KP_MULTIPLY);
00254 GetScript()->CreateVariable("Input.IC_KP_MINUS", IC_KP_MINUS);
00255 GetScript()->CreateVariable("Input.IC_KP_PLUS", IC_KP_PLUS);
00256 GetScript()->CreateVariable("Input.IC_KP_ENTER", IC_KP_ENTER);
00257
00258
00259 GetScript()->CreateVariable("Input.IC_UP", IC_UP);
00260 GetScript()->CreateVariable("Input.IC_DOWN", IC_DOWN);
00261 GetScript()->CreateVariable("Input.IC_LEFT", IC_LEFT);
00262 GetScript()->CreateVariable("Input.IC_RIGHT", IC_RIGHT);
00263 GetScript()->CreateVariable("Input.IC_INSERT", IC_INSERT);
00264 GetScript()->CreateVariable("Input.IC_DELETE", IC_DELETE);
00265 GetScript()->CreateVariable("Input.IC_HOME", IC_HOME);
00266 GetScript()->CreateVariable("Input.IC_END", IC_END);
00267 GetScript()->CreateVariable("Input.IC_PAGEUP", IC_PAGEUP);
00268 GetScript()->CreateVariable("Input.IC_PAGEDOWN", IC_PAGEDOWN);
00269
00270
00271 GetScript()->CreateVariable("Input.IC_NUMLOCK", IC_NUMLOCK);
00272 GetScript()->CreateVariable("Input.IC_CAPSLOCK", IC_CAPSLOCK);
00273 GetScript()->CreateVariable("Input.IC_SCROLLOCK", IC_SCROLLOCK);
00274 GetScript()->CreateVariable("Input.IC_LSHIFT", IC_LSHIFT);
00275 GetScript()->CreateVariable("Input.IC_RSHIFT", IC_RSHIFT);
00276 GetScript()->CreateVariable("Input.IC_LCTRL", IC_LCTRL);
00277 GetScript()->CreateVariable("Input.IC_RCTRL", IC_RCTRL);
00278 GetScript()->CreateVariable("Input.IC_LALT", IC_LALT);
00279 GetScript()->CreateVariable("Input.IC_RALT", IC_RALT);
00280 GetScript()->CreateVariable("Input.IC_LSUPER", IC_LSUPER);
00281 GetScript()->CreateVariable("Input.IC_RSUPER", IC_RSUPER);
00282
00283
00284 GetScript()->CreateVariable("Input.IC_ESCAPE", IC_ESCAPE);
00285 GetScript()->CreateVariable("Input.IC_PRINT", IC_PRINT);
00286 GetScript()->CreateVariable("Input.IC_PAUSE", IC_PAUSE);
00287 GetScript()->CreateVariable("Input.IC_GRAVE", IC_GRAVE);
00288 GetScript()->CreateVariable("Input.IC_MINUS", IC_MINUS);
00289 GetScript()->CreateVariable("Input.IC_EQUALS", IC_EQUALS);
00290 GetScript()->CreateVariable("Input.IC_BACKSLASH", IC_BACKSLASH);
00291 GetScript()->CreateVariable("Input.IC_BACKSPACE", IC_BACKSPACE);
00292
00293 GetScript()->CreateVariable("Input.IC_TAB", IC_TAB);
00294 GetScript()->CreateVariable("Input.IC_LBRACKET", IC_LBRACKET);
00295 GetScript()->CreateVariable("Input.IC_RBRACKET", IC_RBRACKET);
00296 GetScript()->CreateVariable("Input.IC_RETURN", IC_RETURN);
00297
00298 GetScript()->CreateVariable("Input.IC_SEMICOLON", IC_SEMICOLON);
00299 GetScript()->CreateVariable("Input.IC_APOSTROPHE", IC_APOSTROPHE);
00300
00301 GetScript()->CreateVariable("Input.IC_OEM_102", IC_OEM_102);
00302 GetScript()->CreateVariable("Input.IC_COMMA", IC_COMMA);
00303 GetScript()->CreateVariable("Input.IC_PERIOD", IC_PERIOD);
00304 GetScript()->CreateVariable("Input.IC_SLASH", IC_SLASH);
00305
00306 GetScript()->CreateVariable("Input.IC_SPACE", IC_SPACE);
00307
00308
00309 GetScript()->CreateVariable("Input.IC_MOUSE_LEFT", IC_MOUSE_LEFT);
00310 GetScript()->CreateVariable("Input.IC_MOUSE_RIGHT", IC_MOUSE_RIGHT);
00311 GetScript()->CreateVariable("Input.IC_MOUSE_MIDDLE", IC_MOUSE_MIDDLE);
00312
00313
00314 GetScript()->CreateVariable("Input.IC_AXISX", IC_AXISX);
00315 GetScript()->CreateVariable("Input.IC_AXISY", IC_AXISY);
00316 GetScript()->CreateVariable("Input.IC_AXISZ", IC_AXISZ);
00317
00318
00319 GetScript()->CreateVariable("Input.IC_AXIST", IC_AXIST);
00320
00321
00322 shared_ptr<InputSystem> inputSystem =
00323 shared_dynamic_cast<InputSystem>(GetCore()->New(inputSysName));
00324
00325 if(inputSystem.get() == 0)
00326 {
00327
00328 GetLog()->Error() << "(InputServer) ERROR: unable to create "
00329 << inputSysName << "\n";
00330 return false;
00331 }
00332
00333 inputSystem->SetName("inputsystem");
00334
00335 if (inputSystem->Init(this) == false)
00336 {
00337 GetLog()->Error() << "(InputServer) ERROR: unable to initialize "
00338 << inputSysName << "\n";
00339 Reset();
00340 return false;
00341 }
00342
00343 AddChildReference(inputSystem);
00344
00345
00346 GetScript()->RunInitScript
00347 (
00348 mScanCodeScript,
00349 "lib/kerosin/inputserver",
00350 ScriptServer::IS_COMMON
00351 );
00352
00353 return true;
00354 }
00355
00356 shared_ptr<InputSystem> InputServer::GetInputSystem()
00357 {
00358 shared_ptr<InputSystem> inputSystem = shared_dynamic_cast<InputSystem>
00359 (GetChild("inputsystem"));
00360
00361 return inputSystem;
00362 }
00363
00364
00365 bool InputServer::CreateDevice(const std::string &deviceName)
00366 {
00367 GetLog()->Normal() << "(InputServer) CreateDevice " << deviceName << "\n";
00368
00369 shared_ptr<InputSystem> inputSystem = GetInputSystem();
00370
00371 if (inputSystem.get() == 0)
00372 {
00373 GetLog()->Error()
00374 << "(InputSystem) ERROR: no InputSystem installed\n";
00375 return false;
00376 }
00377
00378 if (inputSystem.get() == 0)
00379 {
00380 return false;
00381 }
00382
00383 return inputSystem->CreateDevice(deviceName);
00384 }
00385
00386 void InputServer::Reset()
00387 {
00388 shared_ptr<InputSystem> inputSystem = GetInputSystem();
00389
00390 if (inputSystem.get() != 0)
00391 {
00392 inputSystem->Unlink();
00393 inputSystem.reset();
00394 }
00395
00396 mScanCodeMap->Reset();
00397 }
00398
00399 bool InputServer::GetInput(Input &input, bool raw)
00400 {
00401 shared_ptr<InputSystem> inputSystem = GetInputSystem();
00402
00403 if (inputSystem.get() == 0)
00404 {
00405 GetLog()->Error()
00406 << "(InputServer) ERROR: no InputSystem installed\n";
00407 input.id = -1;
00408 return false;
00409 }
00410
00411 if (! inputSystem->GetInput(input))
00412 {
00413 input.id = -1;
00414 return false;
00415 }
00416
00417 if (
00418 (input.type == eUser) ||
00419 (raw)
00420 )
00421 {
00422
00423 return true;
00424 }
00425
00426
00427 TBindMap::iterator bindListIter = mBindings.find(input.code);
00428 if (bindListIter == mBindings.end())
00429 {
00430 input.id = -1;
00431 return false;
00432 }
00433
00434
00435 TBindList& bindList = (*bindListIter).second;
00436
00437 for (
00438 TBindList::const_iterator bindIter = bindList.begin();
00439 bindIter != bindList.end();
00440 ++bindIter
00441 )
00442 {
00443 const Bind& bind = (*bindIter);
00444
00445
00446 if (bind.modifier == mModifierState)
00447 {
00448 if (input.type == eButton)
00449 {
00450 if ((bind.event == eKeyUpDown) ||
00451 (bind.event == eKeyUp && input.data.l == 0) ||
00452 (bind.event == eKeyDown && input.data.l == 1)
00453 )
00454 {
00455 input.id = bind.cmd;
00456 return true;
00457 }
00458 } else if (input.type == eAxis)
00459 {
00460 input.id = bind.cmd;
00461 return true;
00462 }
00463 }
00464 }
00465
00466
00467 input.id = -1;
00468 return false;
00469 }
00470
00471 bool InputServer::BindCommand(const std::string &desc, int cmd)
00472 {
00473
00474
00475 Bind bind;
00476 if (! ParseBindDescription(bind, desc))
00477 {
00478 return false;
00479 }
00480
00481
00482
00483
00484
00485
00486 bind.cmd = cmd;
00487
00488 mBindings[bind.code].push_front(bind);
00489
00490 return true;
00491 }
00492
00493 void InputServer::SetScanCodeMapping(const std::string &name)
00494 {
00495 mScanCodeScript = name;
00496 }
00497
00498 void InputServer::AddCode(TInputCode ic, const std::string &name, char noMod,
00499 char shiftMod, char altMod)
00500 {
00501 mScanCodeMap->AddCode(ic, name, noMod, shiftMod, altMod);
00502 }
00503
00504 bool InputServer::ParseBindDescription(Bind &bind, const std::string &desc)
00505 {
00506 stringstream s(desc);
00507 string current;
00508 list<string> tokens;
00509
00510 while(!s.eof())
00511 {
00512 getline(s, current,' ');
00513 if (current.size())
00514 {
00515 tokens.push_back(current);
00516 }
00517 }
00518
00519 if (tokens.size() == 0)
00520 {
00521 GetLog()->Error() << "(InputServer) ERROR: Empty bind description? '"
00522 << desc << "'" << endl;
00523 return false;
00524 }
00525
00526
00527 bind.modifier = eNone;
00528
00529 while (tokens.size() > 1)
00530 {
00531 current = tokens.front();
00532 tokens.pop_front();
00533 bind.modifier |= ParseModifier(current);
00534 }
00535
00536
00537 current = tokens.front();
00538 tokens.pop_front();
00539
00540
00541
00542 bind.event = eKeyUpDown;
00543
00544 if (current[0]=='+')
00545 {
00546 bind.event = eKeyDown;
00547 } else if (current[0]=='-')
00548 {
00549 bind.event = eKeyUp;
00550 }
00551
00552 if (bind.event != eKeyUpDown)
00553 {
00554 current = current.substr(1);
00555 }
00556
00557 bind.code = mScanCodeMap->GetCode(current);
00558
00559 if (bind.code == 0)
00560 {
00561 GetLog()->Error() << "ERROR: Erroneous code description '"
00562 << current << "'" << endl;
00563 return false;
00564 }
00565
00566 return true;
00567 }
00568
00569 int InputServer::ParseModifier(const std::string &modifier) const
00570 {
00571 if (modifier == "lshift") return eLShift;
00572 if (modifier == "rshift") return eRShift;
00573 if (modifier == "shift") return eShift;
00574 if (modifier == "lctrl") return eLCtrl;
00575 if (modifier == "rctrl") return eRCtrl;
00576 if (modifier == "ctrl") return eCtrl;
00577 if (modifier == "lalt") return eLAlt;
00578 if (modifier == "ralt") return eRAlt;
00579 if (modifier == "alt") return eAlt;
00580
00581 return eNone;
00582 }
00583
00584 bool InputServer::TranslateCode(TInputCode code,
00585 unsigned long state, char &ch) const
00586 {
00587 state = mModifierState;
00588 return mScanCodeMap->TranslateCode(code, state, ch);
00589 }
00590
00591 void InputServer::Invoke(int cmd)
00592 {
00593 Input input;
00594
00595 input.type = eUser;
00596 input.code = -1;
00597 input.id = cmd;
00598 input.data.l = 0;
00599
00600 shared_ptr<InputSystem> inputSystem = GetInputSystem();
00601 if (inputSystem.get() == 0)
00602 {
00603 GetLog()->Error()
00604 << "(InputServer) ERROR: no InputSystem installed\n";
00605 return;
00606 }
00607
00608 inputSystem->AddInput(input);
00609 }