1、修改cocos2d-x-3.xcocos2dplatformdesktopCCGLView.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.xcocos2dCCEventKeyboard.h
1 public:
2 KeyCode _keyCode;
3 bool _isPressed;
4
5 private:
6 friend class EventListenerKeyboard;