📄 inputserver.cpp
字号:
GetScript()->CreateVariable("Input.IC_RBRACKET", IC_RBRACKET); GetScript()->CreateVariable("Input.IC_RETURN", IC_RETURN); GetScript()->CreateVariable("Input.IC_SEMICOLON", IC_SEMICOLON); GetScript()->CreateVariable("Input.IC_APOSTROPHE", IC_APOSTROPHE); GetScript()->CreateVariable("Input.IC_OEM_102", IC_OEM_102); // German <>| GetScript()->CreateVariable("Input.IC_COMMA", IC_COMMA); GetScript()->CreateVariable("Input.IC_PERIOD", IC_PERIOD); GetScript()->CreateVariable("Input.IC_SLASH", IC_SLASH); GetScript()->CreateVariable("Input.IC_SPACE", IC_SPACE); // mouse buttons GetScript()->CreateVariable("Input.IC_MOUSE_LEFT", IC_MOUSE_LEFT);// left GetScript()->CreateVariable("Input.IC_MOUSE_RIGHT", IC_MOUSE_RIGHT);// right GetScript()->CreateVariable("Input.IC_MOUSE_MIDDLE", IC_MOUSE_MIDDLE); // middle //mouse axis GetScript()->CreateVariable("Input.IC_AXISX", IC_AXISX); GetScript()->CreateVariable("Input.IC_AXISY", IC_AXISY); GetScript()->CreateVariable("Input.IC_AXISZ", IC_AXISZ); // timer GetScript()->CreateVariable("Input.IC_AXIST", IC_AXIST); // create the inputsystem shared_ptr<InputSystem> inputSystem = shared_dynamic_cast<InputSystem>(GetCore()->New(inputSysName)); if(inputSystem.get() == 0) { // could not create InputSystem GetLog()->Error() << "(InputServer) ERROR: unable to create " << inputSysName << "\n"; return false; } inputSystem->SetName("inputsystem"); if (inputSystem->Init(this) == false) { GetLog()->Error() << "(InputServer) ERROR: unable to initialize " << inputSysName << "\n"; Reset(); return false; } AddChildReference(inputSystem); // import the scan code map GetScript()->RunInitScript ( mScanCodeScript, "lib/kerosin/inputserver", ScriptServer::IS_COMMON ); // cache the reference to the input system mInputSystem = inputSystem; return true;}bool InputServer::CreateDevice(const std::string &deviceName){ GetLog()->Normal() << "(InputServer) CreateDevice " << deviceName << "\n"; if (mInputSystem.get() == 0) { GetLog()->Error() << "(InputSystem) ERROR: no InputSystem installed\n"; return false; } return mInputSystem->CreateDevice(deviceName);}void InputServer::Reset(){ if (mInputSystem.get() != 0) { mInputSystem->Unlink(); mInputSystem.reset(); } mScanCodeMap->Reset();}bool InputServer::GetInput(Input &input, bool raw){ if (mInputSystem.get() == 0) { GetLog()->Error() << "(InputServer) ERROR: no InputSystem installed\n"; input.id = -1; return false; } if (! mInputSystem->GetInput(input)) { input.id = -1; return false; } if ( (input.type == eUser) || (raw) ) { // return eUser input return true; } // translate raw input to binding TBindMap::iterator bindListIter = mBindings.find(input.code); if (bindListIter == mBindings.end()) { input.id = -1; return false; } // we have an entry for the scan code TBindList& bindList = (*bindListIter).second; for ( TBindList::const_iterator bindIter = bindList.begin(); bindIter != bindList.end(); ++bindIter ) { const Bind& bind = (*bindIter); //printf("Looking at: %d %d %d", (*bind).code, (*bind).cmd, (*bind).modifier); // JAN: either both are 0 or test with & if ((bind.modifier == 0 && mModifierState == 0) || (bind.modifier & mModifierState)) { if (input.type == eButton) { if ((bind.event == eKeyUpDown) || (bind.event == eKeyUp && input.data.l == 0) || (bind.event == eKeyDown && input.data.l == 1) ) { input.id = bind.cmd; return true; } } else if (input.type == eAxis) { input.id = bind.cmd; return true; } } } input.id = -1; return false;}bool InputServer::BindCommand(const std::string &desc, int cmd){ // first we have to translate the description to a correct Bind // struct Bind bind; if (! ParseBindDescription(bind, desc)) { return false; } // GetLog()->Normal() << "Binding " << cmd << endl; // GetLog()->Normal() << " code: " << bind.code << endl; // GetLog()->Normal() << " modifier: " << bind.modifier << endl; // GetLog()->Normal() << " event: " << bind.event << endl; bind.cmd = cmd; mBindings[bind.code].push_front(bind); return true;}void InputServer::SetScanCodeMapping(const std::string &name){ mScanCodeScript = name;}void InputServer::AddCode(TInputCode ic, const std::string &name, char noMod, char shiftMod, char altMod){ mScanCodeMap->AddCode(ic, name, noMod, shiftMod, altMod);}bool InputServer::ParseBindDescription(Bind &bind, const std::string &desc){ stringstream s(desc); string current; list<string> tokens; while(!s.eof()) { getline(s, current,' '); if (current.size()) { tokens.push_back(current); } } if (tokens.size() == 0) { GetLog()->Error() << "(InputServer) ERROR: Empty bind description? '" << desc << "'" << endl; return false; } // separated string is in tokens first we handle all the modifiers bind.modifier = eNone; while (tokens.size() > 1) { current = tokens.front(); tokens.pop_front(); bind.modifier |= ParseModifier(current); } // at this point only a single string is in the tokenlist current = tokens.front(); tokens.pop_front(); // current now holds the event to which to bind to, plus (maybe) // its pressed/release modifier bind.event = eKeyUpDown; if (current[0]=='+') { bind.event = eKeyDown; } else if (current[0]=='-') { bind.event = eKeyUp; } if (bind.event != eKeyUpDown) { current = current.substr(1); } bind.code = mScanCodeMap->GetCode(current); if (bind.code == 0) { GetLog()->Error() << "ERROR: Erroneous code description '" << current << "'" << endl; return false; } return true;}int InputServer::ParseModifier(const std::string &modifier) const{ if (modifier == "lshift") return eLShift; if (modifier == "rshift") return eRShift; if (modifier == "shift") return eShift; if (modifier == "lctrl") return eLCtrl; if (modifier == "rctrl") return eRCtrl; if (modifier == "ctrl") return eCtrl; if (modifier == "lalt") return eLAlt; if (modifier == "ralt") return eRAlt; if (modifier == "alt") return eAlt; return eNone;}bool InputServer::TranslateCode(TInputCode code, unsigned long state, char &ch) const{ state = mModifierState; return mScanCodeMap->TranslateCode(code, state, ch);}void InputServer::Invoke(int cmd){ Input input; input.type = eUser; input.code = -1; input.id = cmd; input.data.l = 0; if (mInputSystem.get() == 0) { GetLog()->Error() << "(InputServer) ERROR: no InputSystem installed\n"; return; } mInputSystem->AddInput(input);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -