Android back button

Android back button
0.0 0


Is there a way to interface with the android back button? Is there support in cocos2dx, or will I have to build the JNI layer myself? If so, is there an example of this?


Please overload CCLayer::backKeyClicked() method. And don’t forget to call this->isKeypadEnabled(true) in MyLayer::init()


Is android back button mapped on some key under WIN?


Sorry, haven’t mapped :frowning:


thanks Walzer!


Sorry, but the overload method name is CCLayer::keyBackClicked().


This topic may help you -


Zhe Wang wrote:

Please overload CCLayer::backKeyClicked() method. And don’t forget to call this~~>isKeypadEnabled in MyLayer::init
I think you have a bit confuse, this~~>setKeypadEnabled(true); not isKeypadEnabled(true).


You can use Shift + F1 key for back key in Windows.


Just overload Layer:: onKeyReleased method. A simple example just like this.
void YourLayer::onEnter()
//add listener
auto pKeybackListener = EventListenerKeyboard::create();
pKeybackListener->onKeyReleased = CC_CALLBACK_2(YourLayer::onKeyReleased, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(pKeybackListener, this);

void YourLayer::onExit()
//remove listener

void YourLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event *pEvent)
//compare key code
if(keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
//insert your code here


This works as Android buttons in Windows emuliator for me:

PC keyboard equivalents to Android hard keys
Back	== Esc
Home	== Alt+Esc   ||    Windows+Esc
Menu	== Context Menu key   ||  Ctrl+Esc
Search	== hold Context Menu key   ||   Windows+Space
Quick Launch ==	Windows key + <letter>
Volume	== multimedia keys