diff --git a/cocos2dx/keyboard_dispatcher/CCKeyboardDispatcher.cpp b/cocos2dx/keyboard_dispatcher/CCKeyboardDispatcher.cpp index fbb089d176..42146f4dd8 100644 --- a/cocos2dx/keyboard_dispatcher/CCKeyboardDispatcher.cpp +++ b/cocos2dx/keyboard_dispatcher/CCKeyboardDispatcher.cpp @@ -54,11 +54,11 @@ void KeyboardDispatcher::setKeyReleaseDelegate(KeyboardDelegate delegate) bool KeyboardDispatcher::dispatchKeyboardEvent(int keyCode, bool pressed) { - if (_keyPressDelegate != NULL && pressed) + if (_keyPressDelegate != nullptr && pressed) { _keyPressDelegate(keyCode); } - else if (_keyReleaseDelegate != NULL) + else if (_keyReleaseDelegate != nullptr ) { _keyReleaseDelegate(keyCode); } diff --git a/cocos2dx/platform/mac/CCEventDispatcher.mm b/cocos2dx/platform/mac/CCEventDispatcher.mm index 8f1d2fcdf3..76fc04e4c6 100644 --- a/cocos2dx/platform/mac/CCEventDispatcher.mm +++ b/cocos2dx/platform/mac/CCEventDispatcher.mm @@ -505,9 +505,8 @@ static int eventQueueCount; { if( dispatchEvents_ ) { tListEntry *entry, *tmp; + cocos2d::Director::sharedDirector()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, true); - cocos2d::KeyboardDispatcher *kbDisp = cocos2d::Director::sharedDirector()->getKeyboardDispatcher(); - kbDisp->dispatchKeyboardEvent(event.keyCode, true); DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { if ( entry->flags & kImplementsKeyDown ) { void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event]; @@ -522,9 +521,8 @@ static int eventQueueCount; { if( dispatchEvents_ ) { tListEntry *entry, *tmp; - - cocos2d::KeyboardDispatcher *kbDisp = cocos2d::Director::sharedDirector()->getKeyboardDispatcher(); - kbDisp->dispatchKeyboardEvent(event.keyCode, true); + cocos2d::Director::sharedDirector()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, false); + DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { if ( entry->flags & kImplementsKeyUp ) { void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event]; diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 26c9ef36b4..c05634bee7 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -32,6 +32,9 @@ THE SOFTWARE. #include "keypad_dispatcher/CCKeypadDispatcher.h" #include "support/CCPointExtension.h" #include "CCApplication.h" +#ifdef CC_KEYBOARD_SUPPORT +#include "keyboard_dispatcher/CCKeyboardDispatcher.h" +#endif NS_CC_BEGIN @@ -449,6 +452,9 @@ LRESULT EGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) } break; case WM_KEYDOWN: +#ifdef CC_KEYBOARD_SUPPORT + Director::sharedDirector()->getKeyboardDispatcher()->dispatchKeyboardEvent(wParam, true); +#endif if (wParam == VK_F1 || wParam == VK_F2) { Director* pDirector = Director::sharedDirector(); @@ -466,6 +472,9 @@ LRESULT EGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) } break; case WM_KEYUP: +#ifdef CC_KEYBOARD_SUPPORT + Director::sharedDirector()->getKeyboardDispatcher()->dispatchKeyboardEvent(wParam, false); +#endif if ( _lpfnAccelerometerKeyHook!=NULL ) { (*_lpfnAccelerometerKeyHook)( message,wParam,lParam );