开发者

Object (KeyEvent key) to String (Java)

I have someth开发者_如何转开发ing similar to the following: An object with the value of KeyEvent.VK_G. How can I get the key letter from that object (as a String)?


By using KeyEvent.getKeyChar() (see http://download.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html#getKeyChar()).


Is this what you want to do?

int someKeyCode = KeyEvent.VK_G;
Object someKeyCodeObject = new Integer(someKeyCode);
String keyString = KeyEvent.getKeyText((Integer)someKeyCodeObject);

Which would give "G" in this case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜