首页 > 代码库 > cocos2d-x3.x windows环境下 textfield无法处理TEXTFIELD_EVENT_DELETE_BACKWARD事件

cocos2d-x3.x windows环境下 textfield无法处理TEXTFIELD_EVENT_DELETE_BACKWARD事件

1、修改cocos2d-x-3.x\cocos\2d\platform\desktop\CCGLView.cpp   onGLFWKeyCallback函数 

 1 static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) 2     { 3         if (_view) 4             _view->onGLFWKeyCallback(window, key, scancode, action, mods); 5              6         if (GLFW_REPEAT != action)  7         { 8             EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action); 9             if ((EventKeyboard::KeyCode::KEY_BACKSPACE == event._keyCode) && event._isPressed) 10             {  11                 IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();  12             }   13             else  14             { 15                 auto dispatcher = Director::getInstance()->getEventDispatcher();  dispatcher->dispatchEvent(&event); 16             }  17         } 18     }

2、在CCGLView.cpp中 把声明g_keyCodeMap放到最前面, 如下这句:

1 static std::unordered_map<int, EventKeyboard::KeyCode> g_keyCodeMap;

3、修改cocos2d-x-3.x\cocos\2d\CCEventKeyboard.h

1 public:2     KeyCode _keyCode;3     bool _isPressed;4     5 private:6     friend class EventListenerKeyboard;

 

cocos2d-x3.x windows环境下 textfield无法处理TEXTFIELD_EVENT_DELETE_BACKWARD事件