开发者

Object (KeyEvent key) to String (Java)

开发者 https://www.devze.com 2023-04-08 19:15 出处:网络
I have someth开发者_如何转开发ing similar to the following: An object with the value of KeyEvent.VK_G.

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

精彩评论

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