Convert char into KeyEvent on Android

567 views Asked by At

I cannot manage to get a character recognized by the KeyEvent.keyCodeToString(keyEvent) function.
I've tried:

KeyEvent.keyCodeToString(Character.getNumericValue('5')); // Output: KEYCODE_CALL
KeyEvent.keyCodeToString(Integer.parseInt(String.valueOf(Character.getNumericValue('5')))); // Output: KEYCODE_CALL

The correct output will be used to compare with the keyCode variable in the function I'm working on. Thanks!

1

There are 1 answers

3
Gabe Sechan On

That's working as expected. 5 is KEYCODE_CALL. The number 5 is KEYCODE_5, which has a numeric value of 12.

I'm not sure why you're using KEYCODE constants at all though. There's almost certainly better ways to do it, especially since almost no keyboards send KEYCODE events.