After owning a Motorola Droid for two years I put a great importance on handling hardware keyboard events in my applications. However, most apps do not handle such events properly. An example: most non-AOSP calculator apps make it necessary to press the shift key in order to use the number row. Why? Perhaps it is because KeyEvent.KEYCODE_0 does not handle when the key that should be zero is pressed. The simple option would be to map keys like ‘P’ to ‘0′, but that is not very dynamic, and what if the next Android keyboard phone maps the keys otherwise?
The solution is to check with the keyboard meta state, and it is fairly simple! If you know what key you want to the code below should help you handling keyboard meta states:
final char[] mZeroChar = { '0' };
if (event.getMatch(mZeroChar, event.getMetaState()) == mZeroChar[0])
{
// The key that is zero in some meta state was pressed.
}
That’s it, and that can be applied to any key you need. Hope that helps, and as always happy coding.