cocos2dx 响应windows键盘事件

#include <windows.h>
#define KEY_DOWN(vk_code) (GetAsyncKeyState(vk_code) & 0x8000 ? 1 : 0)
#define KEY_UP(vk_code) (GetAsyncKeyState(vk_code) & 0x8000 ? 0 : 1)

    if( KEY_DOWN( VK_DOWN ) )
    {
        SceneGaming * scene = (SceneGaming *)SceneManager::getSingleton().getGamingScene();
        LayerGamingPause * pLayerGamingPause = scene->getLayerPause();
        pLayerGamingPause->setVisible( true );
        // scene->pauseSchedulerAndActions();


    }



另一种方式:


在初始化时先注册回调:


CCDirector::sharedDirector()->getOpenGLView()->setAccelerometerKeyHook( XXX::keyboardHook );

XXX:keyboardHook实现如下:


void XXX::keyboardHook( UINT message,WPARAM wParam, LPARAM lParam )
{

    switch (message)
    {
        case WM_KEYDOWN:
            return;
        case WM_KEYUP:
            // wParam 即为键盘字母码,在此处理即可
        return;
    }
}


你可能感兴趣的:(cocos2dx 响应windows键盘事件)