iOS app running on MAC os Big Sur and keyboard events

I wanted to make my games available on MAC OS. So instead of creating an official MAC app, I wanted to use the new feature available from Big Sur allowing you to basically run any iOS APP on a MAC without any work. (or at least less work)

While this is fun in theory, in reality, the game still requires some kind of work to make sense on a MAC. So I basically used the same logic I used for the PC version with enabling keyboard shortcuts and movement (AWSD, Space, Enter etc). I can easily detect if the iOS game is running on a MAC to enable different interface and logic etc.

The problem is: There are no keyboard events fired. Nor mouse scrolling or “right click”. As if the code was doing nothing on iOS (I assume because iOS normally do not have a physical keyboard).

Anyone has an idea how to enable physical keyboard events ?

Thanks

Event Dispatch - Keyboard events docs might help.

@slackmoehrle My problem is not with implementing the keyboard events, that has been done months ago. My games are already being sold on STEAM. Problem is that when trying to run the ios APP on a M1 chip Big sur OS, the events are not fired. (At least when running it through XCode and using target “My Mac (Designed for iPad)”. Haven’t tried yet with the real app from the app store

Oh. I gotcha. I have a text adventure game that is running fine on Big Sur. Have you tried cpp-tests?

Hi, sorry for late response, I wanted to check on the real app on the real store if it was working and if this was not just an emulator issue. But I still have the same problem :frowning:

I did not test the cpp-tests yet. However, the code is pretty simple:

m_KeyboardListener = EventListenerKeyboard::create();
m_KeyboardListener->onKeyPressed = [&](EventKeyboard::KeyCode keyCode, Event* event)
{

}
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(m_KeyboardListener, Scene);

And nothing is fired. This works well on PC.

Important note: This is not a MAC version of the app, this is an iOS app running on a MAC (with the new M1 chip allowing ios APP to run on a MAC)

I’m not sure any of us has the equipment at this time. I’ll ask.

Ok thanks. I assume the issue might be there

cocos2d-x doesn’t support m1, so can the iOS app run on m1?

Every single application on the iOS store is now available on a MAC that has a M1 chip. (Unless, as a developer, you manually decide to opt out of this feature for your apps). My games are available on MAC via this new features and they work properly. I just wanted to add the “PC” code to it in order to have a better usability for the players and allowing them to use the keyboard shortcuts/movement etc.

However, the keyboard events do not seem to be fired.

Got it, i do not have m1. My coworker will take a look.

One of our engineers suggested to review this document: Apple Developer Documentation

It say that:
Your app’s interactions rely extensively on touch input that you can’t replicate with the keyboard or other input.

He misinterpreted this sentence…

It is in the section “Does it make sense to make your build available for MAC”

And this sentence:

“Your app’s interactions rely extensively on touch input that you can’t replicate with the keyboard or other input.”

Only mean that if you cannot replicate the touch with the keyboard, then it does not make sense (You can read in between the line that you can actually support the keyboard)

Plus in the same article, they mention in the section called " Adopt Features that Offer a Better User Experience":

“Add iOS keyboard support to your app and create keyboard-based shortcuts for your app’s features. Users can access these shortcuts on any iOS or macOS device with a connected keyboard.”

So overall, Keyboard should be supported

I’ll send your reply and help to clarify.