Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listen to every key event on a soft keyboard android

I wan't to listen to the soft keyboard event. I've tried setOnKeyListener and setKeyListener and both of them don't work. Does anyone know how to listen to the soft keyboard?

like image 826
Tony Lin Avatar asked Dec 12 '22 04:12

Tony Lin


1 Answers

Assuming you're using a soft keyboard on a newer Android version, then the following blurb from the KeyEvent reference explains key limitations in getting soft key events.

"As soft input methods can use multiple and inventive ways of inputting text, there is no guarantee that any key press on a soft keyboard will generate a key event: this is left to the IME's discretion, and in fact sending such events is discouraged. You should never rely on receiving KeyEvents for any key on a soft input method. In particular, the default software keyboard will never send any key event to any application targetting Jelly Bean or later, and will only send events for some presses of the delete and return keys to applications targetting Ice Cream Sandwich or earlier. Be aware that other software input methods may never send key events regardless of the version. Consider using editor actions like IME_ACTION_DONE if you need specific interaction with the software keyboard, as it gives more visibility to the user as to how your application will react to key presses."

I think using the TextWatcher interface is probably as close as the you're going to get to what you want.

like image 71
scottt Avatar answered Jan 17 '23 12:01

scottt