Reputation: 21
I came across the problem with keyboard event listener - all keys work fine except the Enter key. Here's my code:
listener = EventListenerKeyboard::create();
listener->onKeyPressed = CC_CALLBACK_2(PauseMenu::InputHandler, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
......
void PauseMenu::InputHandler(EventKeyboard::KeyCode keyCode, Event* event)
{
switch (keyCode)
{
case EventKeyboard::KeyCode::KEY_DOWN_ARROW:
Next(); break;
case EventKeyboard::KeyCode::KEY_UP_ARROW:
Previous(); break;
case EventKeyboard::KeyCode::KEY_ENTER:
Select(); break;
}
}
I've tried to set different keys for needed action and they work fine. Could anyone explain what could be the reason of this problem? Thanks in advance
Upvotes: 1
Views: 1311
Reputation: 64477
Notice that the ENTER key is the one on the numpad (lower-right corner of most keyboards), the RETURN key is the one above the RIGHT-SHIFT key and is perhaps what you are looking for instead.
The ENTER and RETURN keys typically are assigned different keycodes in game engines. Check if there's a KEY_RETURN
type and try it with that.
Upvotes: 2