简体   繁体   中英

Convert char into KeyEvent on Android

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM