开发者

How to use keyCodeToString() in Android

开发者 https://www.devze.com 2023-03-18 12:27 出处:网络
I want to convert keycode to its symbolic name . i.e. KEYCODE_A . A keycode is 29. In y code, onKeyDown(), when I press key \'A\', I want to display what I pressed is \'A\', n开发者_运维百科ot only th

I want to convert keycode to its symbolic name . i.e. KEYCODE_A . A keycode is 29. In y code, onKeyDown(), when I press key 'A', I want to display what I pressed is 'A', n开发者_运维百科ot only the keycode '29'. I look up in developer.android.com, I found there is a way keyCodeToString(), it seems can do that. Any ideas how to use it?

Thanks a lot. Best, Qin


I don't think that keyCodeToString() is what you want. This will return "KEYCODE_A", when A is pressed. Perhaps you want to try getNumber or getUnicodeChar.

Since keyCodeToString is a static method, you can use it like this:

String keyCodeStr = KeyEvent.keyCodeToString(keyCode);
0

精彩评论

暂无评论...
验证码 换一张
取 消