Navigate Between EditBox using NEXT Key

Navigate Between EditBox using NEXT Key



In my game I have a registration form and I’d like to have the user navigate between all the EditBox fields using the “Next” key on their virtual keyboard.
I’ve implemented the editBoxReturn method, from the EditBoxDelegate class. However, I’m having trouble setting the focus on the next EditBox.

My code is this:

void RegisterScene::editBoxReturn(ui::EditBox* editBox)
        if (txtUser == editBox) {
            this->txtPass->touchDownAction(NULL, cocos2d::ui::Widget::TouchEventType::ENDED);
        } else if (txtPass == editBox) {
            this->txtConfirm->touchDownAction(NULL, cocos2d::ui::Widget::TouchEventType::ENDED);


The code works only for the first EditBox, and when the focus is set on the txtPass I can’t dismiss the keyboard anymore, and I can’t type anything on the EditBox.

Can someone help me? I feel like this is not the proper way to set the focus.
I’ve tried the requestFocus method but It didn’t work either.

Thanks for the help!


I’m having the same problem, would really like to be able to move to the “next” editbox in a list. I can move to the next field, but can’t type. I’m working with cocos2d-x 3.16 (c++).

[update, I’ve found a way to go to the next field by calling “onExit” on the current editBox and then an event on the next one. Now I’ll look for a way to be able to close the editbox if I click outside. If I find a solution, I’ll post it]

Got it! Works great on iOS, and I’ll test it in Windows asap.

  1. when creating an EditBox, set return type to NEXT

  2. in your editBoxEditingDidEndWithAction(EditBox *box, EditBoxEndAction action) method, check for the action.

  • if action == TAB_TO_NEXT, go to the next field
  • else (they hit return on desktop or tapped outside on iOS), don’t advance, just close

Update :frowning: Sadly, while this works for iOS, it doesn’t for Windows (I haven’t tested Mac yet), and of course, this functionality is more important on desktop. I hope I can find a workaround. If necessary, I’ll see if I need to modify any of the EditBox classes.