kingBook

导航

android平台菜单返回键监听

//声明

void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);

//实现

//按键控制(检测onKeyReleased有反应)
auto listener = EventListenerKeyboard::create();
listener->onKeyReleased = CC_CALLBACK_2(MenuLayer::onKeyReleased, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
void MenuLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
    switch(keyCode)
    {
    //监听返回键
    case EventKeyboard::KeyCode::KEY_ESCAPE:

         Director::getInstance()->end();
        break;
    //监听menu键
    case EventKeyboard::KeyCode::KEY_MENU:
        break;
    }
} 

 

posted on 2016-05-21 19:12  kingBook  阅读(532)  评论(0编辑  收藏  举报