Merge pull request #3054 from simpliplant/windows_keyboard_support

Hardware keyboard support (Windows support + Mac fix)
This commit is contained in:
minggo 2013-07-03 23:37:13 -07:00
commit ddf54a4f49
3 changed files with 14 additions and 7 deletions

View File

@ -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);
}

View File

@ -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::Director::sharedDirector()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, false);
cocos2d::KeyboardDispatcher *kbDisp = cocos2d::Director::sharedDirector()->getKeyboardDispatcher();
kbDisp->dispatchKeyboardEvent(event.keyCode, true);
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
if ( entry->flags & kImplementsKeyUp ) {
void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event];

View File

@ -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 );