0

Given an integer which comes from KeyEvent.VK_[value], such as KeyEvent.VK_SPACE or KeyEVENT.VK_F3, I'd like to convert it to the String of the key.

For example keyIntToString(KeyEvent.VK_SPACE) would return "Space"

How can I do this?


I've tried

KeyEvent.getKeyText(KeyEvent.VK_SPACE);

In the terminal, if I print that, I get "Space". In Eclipse if I print that, I get "?". In a JLabel if I display that, I get a square.

What I really want is to get it into a JLabel. How do I do this?

CodeGuy
  • 28,427
  • 76
  • 200
  • 317

1 Answers1

1

Something like this

String keyString = KeyEvent.getKeyText(KeyEvent.VK_SPACE);
System.out.println("keyString " + keyString);

Also you can use getChar method in KeyEvent

vels4j
  • 11,208
  • 5
  • 38
  • 63