diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 4754b1892c..49b1690250 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -35,12 +35,20 @@ THE SOFTWARE. NS_CC_BEGIN -static std::map g_keyCodeMap;// = { +struct keyCodeItem +{ + int glfwKeyCode; + KeyboardEvent::KeyCode keyCode; +}; + +static std::map g_keyCodeMap; + +static keyCodeItem g_keyCodeStructArray[] = { /* The unknown key */ - // make_pair( GLFW_KEY_UNKNOWN , KeyboardEvent::KeyCode::KEY_NONE ), + { GLFW_KEY_UNKNOWN , KeyboardEvent::KeyCode::KEY_NONE }, /* Printable keys */ - /* + { GLFW_KEY_SPACE , KeyboardEvent::KeyCode::KEY_SPACE }, { GLFW_KEY_APOSTROPHE , KeyboardEvent::KeyCode::KEY_APOSTROPHE }, { GLFW_KEY_COMMA , KeyboardEvent::KeyCode::KEY_COMMA }, @@ -92,7 +100,7 @@ static std::map g_keyCodeMap;// = { { GLFW_KEY_WORLD_1 , KeyboardEvent::KeyCode::KEY_GRAVE }, { GLFW_KEY_WORLD_2 , KeyboardEvent::KeyCode::KEY_NONE }, - /* Function keys *//* + /* Function keys */ { GLFW_KEY_ESCAPE , KeyboardEvent::KeyCode::KEY_ESCAPE }, { GLFW_KEY_ENTER , KeyboardEvent::KeyCode::KEY_KP_ENTER }, { GLFW_KEY_TAB , KeyboardEvent::KeyCode::KEY_TAB }, @@ -163,8 +171,8 @@ static std::map g_keyCodeMap;// = { { GLFW_KEY_RIGHT_ALT , KeyboardEvent::KeyCode::KEY_ALT }, { GLFW_KEY_RIGHT_SUPER , KeyboardEvent::KeyCode::KEY_HYPER }, { GLFW_KEY_MENU , KeyboardEvent::KeyCode::KEY_MENU }, - { GLFW_KEY_LAST , KeyboardEvent::KeyCode::KEY_NONE }*/ -//}; + { GLFW_KEY_LAST , KeyboardEvent::KeyCode::KEY_NONE } +}; #if(_MSC_VER >= 1600) // Visual Studio 2010 or higher version. // Windows Touch define @@ -368,6 +376,10 @@ EGLView::EGLView() { CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n"); s_pEglView = this; + for (auto& item : g_keyCodeStructArray) + { + g_keyCodeMap.insert(std::make_pair(item.glfwKeyCode, item.keyCode)); + } strcpy(_viewName, "Cocos2dxWin32"); glfwSetErrorCallback(EGLViewEventHandler::OnGLFWError); glfwInit(); diff --git a/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.cpp b/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.cpp index f5b2a55f30..53c1d8248b 100644 --- a/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.cpp +++ b/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.cpp @@ -1,7 +1,5 @@ #include "KeyboardTest.h" -#ifdef CC_KEYBOARD_SUPPORT - KeyboardTest::KeyboardTest() { auto s = Director::getInstance()->getWinSize(); @@ -43,4 +41,3 @@ void KeyboardTestScene::runThisTest() layer->release(); } -#endif diff --git a/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h b/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h index 56f322f4fd..d3db8eb9d1 100644 --- a/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h +++ b/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h @@ -1,8 +1,6 @@ #ifndef _KEYBOARD_TEST_H_ #define _KEYBOARD_TEST_H_ -#ifdef CC_KEYBOARD_SUPPORT - #include "cocos2d.h" #include "../testBasic.h" @@ -25,6 +23,5 @@ public: virtual void runThisTest(); }; -#endif #endif diff --git a/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.cpp b/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.cpp index 3f46ecca1d..3878a2f81b 100644 --- a/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.cpp +++ b/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.cpp @@ -7,7 +7,7 @@ KeypadTest::KeypadTest() addChild(label, 0); label->setPosition( Point(s.width/2, s.height-50) ); - setKeypadEnabled(true); + setKeyboardEnabled(true); // create a label to display the tip string _label = LabelTTF::create("Please press any key...", "Arial", 22); diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index f3ad2162a7..5d9f13bb17 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -50,9 +50,7 @@ struct { { "FileUtilsTest", []() { return new FileUtilsTestScene(); } }, { "FontTest", []() { return new FontTestScene(); } }, { "IntervalTest", [](){return new IntervalTestScene(); } }, -#ifdef CC_KEYBOARD_SUPPORT { "KeyboardTest", []() { return new KeyboardTestScene(); } }, -#endif #if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA) { "KeypadTest", []() { return new KeypadTestScene(); } }, #endif diff --git a/samples/Cpp/TestCpp/Classes/tests.h b/samples/Cpp/TestCpp/Classes/tests.h index 724f95276f..851e6a3749 100644 --- a/samples/Cpp/TestCpp/Classes/tests.h +++ b/samples/Cpp/TestCpp/Classes/tests.h @@ -31,9 +31,7 @@ #include "EffectsAdvancedTest/EffectsAdvancedTest.h" #include "AccelerometerTest/AccelerometerTest.h" #include "KeypadTest/KeypadTest.h" -#ifdef CC_KEYBOARD_SUPPORT #include "KeyboardTest/KeyboardTest.h" -#endif #include "PerformanceTest/PerformanceTest.h" #include "ZwoptexTest/ZwoptexTest.h" #include "CocosDenshionTest/CocosDenshionTest.h" diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index d8c38569e3..d87a186dec 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -177,6 +177,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + @@ -311,6 +312,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index cf47e0d936..3eef58db2b 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -295,6 +295,9 @@ {24f044ee-09a6-406b-98d7-8d5d759e5bb1} + + {8d7d37cd-5cc2-4a7d-9bd2-7b5c928adbb5} + @@ -685,6 +688,9 @@ Classes\ExtensionsTest\CocoStudioGUITest + + Classes\KeyboardTest + @@ -1252,5 +1258,8 @@ Classes\ExtensionsTest\CocoStudioGUITest + + Classes\KeyboardTest + \ No newline at end of file