keyEvent 里面 哪个按钮才是手机返回按键啊。。。 求解
cocos2d-x 3.2版本的。
keyEvent 里面 哪个按钮才是手机返回按键啊。。。 求解
cocos2d-x 3.2版本的。
EventKeyboard::KeyCode::KEY_ESCAPE
在要监听的Scene的init方法中添加一下代码:
auto listener = EventListenerKeyboard::create();
listener->onKeyReleased =&](EventKeyboard::KeyCode keyCode, Event* event)
{
//不同手机的keycode可能不一样,为了安全全写了
if(EventKeyboard::KeyCode::KEY_RETURN == keyCode || EventKeyboard::KeyCode::KEY_ESCAPE == keyCode || EventKeyboard::KeyCode::KEY_BACKSPACE == keyCode)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
};
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);