Keyboard Input Event

Is there a way to listen to keypress events on the keyboard?

I’ve added [lua]print( "KB EVENT: " … event.phase )[/lua] into my text field handler but only see the began, ended, submitted phases. Nothing appears in there as I tap the keyboard keys.

There is no “return” button on the numeric keyboard so I want to dismiss the keyboard automatically after the user has keyed in a 4 digit number by checking [lua]if txtField.text == 4 then hideKB()[/lua] [import]uid: 11393 topic_id: 4552 reply_id: 304552[/import]

Did you find an answer to this? I am trying to trap the keys that are pressed in order to make a progressive search. The answer to your question would go a long way to help me. [import]uid: 97768 topic_id: 4552 reply_id: 86704[/import]

Yes - you can do these things. In your textField event handler, watch for event.phase == ‘editing’. Other values you can see at that time are event.oldText (before whatever key(s) were just pressed) and event.newText (after whatever key(s) were just pressed). I am not positive that this occurs on every keypress - given that one of the parameters to the event handler is also event.newCharacters - the name at least hints that it may be more than one. You also get event.text and event.text:len() == 4 would tell you that they have entered 4 characters (may not be digits I guess). Given that you defined the keyboard with something like kb = display.newTextField(…), to automatically dismiss the keyboard use native.setKeyboardFocus(nil) and then kb:removeSelf(). This is what is working for me anyway. [import]uid: 117477 topic_id: 4552 reply_id: 86710[/import]

Thank you so much. I will be playing with all of those, you are a life saver :slight_smile: [import]uid: 97768 topic_id: 4552 reply_id: 86857[/import]