Implementing SoftKeyboardEvent in non-legacy

We’re just finishing up a large OpenFL based project and (as ever when you’re up against it) I suddenly realised we need some way of detecting soft keyboard dismissal for iOS and Android since we have totally custom textFields (sigh, don’t ask) that need to respond appropriately.

AS3 supports SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE etc. so I added this functionality to legacy (which we’re using for our first version) which proved pretty trivial thankfully. So everything’s fine at that end.

However, for the sake of completeness I thought it might be an idea to add it to the current (non-legacy) version and so had a poke around though the code (which is looking really nicely put together structurally, great job there). I could just jump in but I thought perhaps it might be an idea to ask advice as to the right approach here (@singmajesty etc.) before wading in and wasting everyone’s time:

On the Lime side of things, would it make sense to create a SoftKeyboardEvent class in the style of JoystickEvent etc. and then have a lime_soft_keyboard_event_manager_register type function which registers a callback as you do for the various other events? Then trigger SoftKeyboardEvent::Dispatch from the appropriate application class? It seems bit of overkill to create a whole new type of Event for something like this, but it doesn’t seem to fit anywhere else and it seems to fit with the general scheme.

Then over in OpenFL I presume you’d have some sort of onSoftKeyboardActivate/Deactivate function in Stage that can then do the business of generating the flash style event and sending it on its way. Does that make sense? Or am I barking up the wrong tree?

I had never heard of SoftKeyboardEvent before, but I guess this makes sense :smile:

We are using the SDL2 library for all our desktop and mobile targets at the moment. It has something called “text input events” in order to handle more complex text input, which is really important for Unicode.

At the moment, we have a window.enableTextEvents property which starts the text input process. If there is a virtual keyboard, it should show at that time. Now the tricky about the ACTIVATE/DEACTIVATE events is we do not have any system notification API for knowing if it was hidden. Looking more deeply at SDL, it appears there is SDL_IsTextInputActive and SDL_IsScreenKeyboardShown, but these are methods we need to poll.

Perhaps there is a way we can check for a screen keyboard when we enable text input, then we could notify (on the OpenFL side) of an ACTIVATE event type. As for deactivate, perhaps we can poll while the text input is enabled (like every 300ms or so) and then dispatch the DEACTIVATE when that comes through.

So I think we need access to SDL_IsScreenKeyboardShown somewhere in Lime, and we need to decide what to call it on the Lime side. We could also consider Lime-based events when window.enableTextInput changes, or just track it in OpenFL. Lastly, we would wire requests to enable or disable text input (or detecting a user dismissal of soft keyboard input) up to the SoftKeyboardEvent class. So I think we’re mostly there, just a little plumbing and thought to handle this.

What do you think? (and thanks!)