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.
精彩评论