Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top