Hello. I added keyboard support to my game. It works beautifully when I compile the game for Linux (with “cocos compile . -p linux”), but does not work on any Android device. I tried Samsung Galaxy Tab S3 with an external keyboard connected through USB, and Acer Chromebook 11. Curiously, the “back” button works on both and registers as “Esc”.
The code I’m using:
auto keyboardListener = cc::EventListenerKeyboard::create();
keyboardListener->onKeyPressed = [](cc::EventKeyboard::KeyCode keyCode,
cc::Event* event) {
// ...
};
keyboardListener->onKeyReleased = [](cc::EventKeyboard::KeyCode keyCode,
cc::Event* event) {
// ...
};
_eventDispatcher
->addEventListenerWithSceneGraphPriority(keyboardListener, this);
Since the Chromebook does not have a touch screen (which I think is common), that means the game is unplayable.
Some googling suggests that other also had trouble getting the keyboard to work on Android. Is there anything I can try to make it work? Is this even supposed to work?
I’m using cocos2d-x-3.17.2 for the Android build. Would things improve if I upgraded to cocos2d-x 4.0?
Thanks,
Aleksander