⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inputserver.cpp

📁 robocup rcssserver 运行防真机器人足球比赛所用的服务器端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        }    return inputSystem->CreateDevice(deviceName);}void InputServer::Reset(){    shared_ptr<InputSystem> inputSystem = GetInputSystem();    if (inputSystem.get() != 0)        {            inputSystem->Unlink();            inputSystem.reset();        }    mScanCodeMap->Reset();}boolInputServer::GetInput(Input &input, bool raw){    shared_ptr<InputSystem> inputSystem = GetInputSystem();    if (inputSystem.get() == 0)    {        GetLog()->Error()            << "(InputServer) ERROR: no InputSystem installed\n";        input.mId = -1;        return false;    }    if (! inputSystem->GetInput(input))    {        input.mId = -1;        return false;    }    if (        (input.mType == Input::eUser) ||        (raw)        )    {        // return Input::eUser input        return true;    }    // translate raw input to binding    TBindMap::iterator bindListIter = mBindings.find(input.mCode);    if (bindListIter == mBindings.end())    {        input.mId = -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).mCode, (*bind).cmd, (*bind).modifier);        if (bind.modifier == mModifierState)        {#if 0            if (input.mType == Input::eButton)            {                if ((bind.event == eKeyUpDown) ||                    (bind.event == eKeyUp && input.mData.l == 0) ||                    (bind.event == eKeyDown && input.mData.l == 1)                    )#else            const Bind& bind = (*bindIter);            //printf("Looking at: %d %d %d", (*bind).mCode, (*bind).cmd, (*bind).modifier);            if (                (bind.modifier == 0 && mModifierState == 0) ||                (bind.modifier & mModifierState)                )#endif            {                input.mId = bind.cmd;                return true;            }            else if (input.mType == Input::eAxis)            {                input.mId = bind.cmd;                return true;            }        }    }    input.mId = -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(Input::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 = Input::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 Input::eLShift;    if (modifier == "rshift")       return Input::eRShift;    if (modifier == "shift")        return Input::eShift;    if (modifier == "lctrl")        return Input::eLCtrl;    if (modifier == "rctrl")        return Input::eRCtrl;    if (modifier == "ctrl")         return Input::eCtrl;    if (modifier == "lalt")         return Input::eLAlt;    if (modifier == "ralt")         return Input::eRAlt;    if (modifier == "alt")          return Input::eAlt;    return Input::eNone;}bool InputServer::TranslateCode(Input::TInputCode code,                                unsigned long state, char &ch) const{    state = mModifierState;    return mScanCodeMap->TranslateCode(code, state, ch);}void InputServer::Invoke(int cmd){    Input input;    input.mType = Input::eUser;    input.mCode = -1;    input.mId   = cmd;    input.mData.l = 0;    shared_ptr<InputSystem> inputSystem = GetInputSystem();    if (inputSystem.get() == 0)        {            GetLog()->Error()                << "(InputServer) ERROR:  no InputSystem installed\n";            return;        }    inputSystem->AddInput(input);}unsigned int& InputServer::GetModifierState(){    return mModifierState;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -