Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is onKeyUp or onKeyDown not getting called for certain characters?

In my activity, I have an onKeyUp and onKeyDown event handlers, which are called for normal characters and even for some unicode characters like cedilla (ç). But not for others like á, à, ü, é, č, š, ž, è, ...

Why is that? And how can I register those key presses (or better yet, characters)?

I am testing this on a Samsung Galaxy S2 with soft keyboard (samsung and swype keyboards), where accented characters are available with a long key press. It is interesting to note that even cedilla (ç), which is available with the same long press, does get registered with onKeyUp/Down event handler.

I am using onKeyUp/Down on the activity. There is no text box or anything text related on the main view. Just a modified ImageView.

I tested this in an emulator as well (default android image 2.3.3) and behaviour is similar to real device.

like image 913
miha Avatar asked Oct 30 '25 04:10

miha


1 Answers

Through testing, I found the answer. Most unicode characters are handled by onKeyMultiple event handler. If you get

keyCode == KeyEvent.KEYCODE_UNKNOWN &&  event.getAction() == KeyEvent.ACTION_MULTIPLE

Then you can obtain the unicode character by calling event.getCharacters(). It is actually all documented, though a bit hard to find.

like image 120
miha Avatar answered Oct 31 '25 18:10

miha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!