Intercepting back key when the on-screen keyboard is dismissed

Hello,

tl;dr I would like an “ended” event.phase in “userInput” on native.textField/textBox

As the title suggests, I was hoping the engineers would have another look at implementing this?

Currently, no event is triggered in “userInput” when the keyboard is dismissed via back-key while editing a native.textField or native.textBox

I found some old threads referring to this problem,  where the solution ended with what we have now: having the activity slide up when the keyboard is shown and slide down when hidden. (Very nice!)

After a quick google search, I found multiple references to an event in android called OnKeyPreIme.

See here http://stackoverflow.com/a/28719420/5812628

What I want out of this is simply to have an “ended” event.phase be triggered when the user presses the back key. I see this as a pretty common behavior for a lot of android users, myself included.

My app isn’t hindered by lack of this functionality, so this isn’t too important right now, but it would help improve app-flow and presentation for my users.

Hey danielr0,

why not use the normal back button event to get this event?

Would work as the following:

  1. You’ve got a varable which holds the state of the textfield (e.g. “active”, “inactive”)

  2. If you open the textfield, you set it to “active”.

  3. If you close the textfield, you set it to “inactive”.

  4. If the backButton is pressed and the state of the textfield is “active”, you assume that it’s closed now and trigger the event.

The listener for the backbutton would look somewhat like this:

function backButtonListener(event) local phase = event.phase local keyName = event.keyName if keyName == "back" then if phase == "up" then if textfield.state == "active" then                                 textfield.state = "inactive"         --do whatever you need to do end end end return false end Runtime:addEventListener( "key", backButtonListener )

Hope that heps as a starting point :slight_smile:

Sorry, I should have pointed out that my problem was when the the native keyboard is shown, it absorbs all input including the back button, so corona never fires a “key” event.

This means the user can dismiss the keyboard, leaving the textfield/textbox in it’s active state and so it never gets an “ended” event.

I’m relying on these ended events to set up user’s input and tell other objects of the completion.

I believe that the fix I wanted can only be done under the hood.

I would like to get an opinion from a corona dev on the plausibility of the solution I suggested above, before I go making a feature request.

Edit: When I think about it, if the fix is possible: it would be appropriate to have a different event such as “dismissed” + “ended”, and not “submitted”

Hey danielr0,

why not use the normal back button event to get this event?

Would work as the following:

  1. You’ve got a varable which holds the state of the textfield (e.g. “active”, “inactive”)

  2. If you open the textfield, you set it to “active”.

  3. If you close the textfield, you set it to “inactive”.

  4. If the backButton is pressed and the state of the textfield is “active”, you assume that it’s closed now and trigger the event.

The listener for the backbutton would look somewhat like this:

function backButtonListener(event) local phase = event.phase local keyName = event.keyName if keyName == "back" then if phase == "up" then if textfield.state == "active" then                                 textfield.state = "inactive"         --do whatever you need to do end end end return false end Runtime:addEventListener( "key", backButtonListener )

Hope that heps as a starting point :slight_smile:

Sorry, I should have pointed out that my problem was when the the native keyboard is shown, it absorbs all input including the back button, so corona never fires a “key” event.

This means the user can dismiss the keyboard, leaving the textfield/textbox in it’s active state and so it never gets an “ended” event.

I’m relying on these ended events to set up user’s input and tell other objects of the completion.

I believe that the fix I wanted can only be done under the hood.

I would like to get an opinion from a corona dev on the plausibility of the solution I suggested above, before I go making a feature request.

Edit: When I think about it, if the fix is possible: it would be appropriate to have a different event such as “dismissed” + “ended”, and not “submitted”