Noah Wilhelm
Noah Wilhelm

Reputation: 90

Convert VKCode to String Java

As the title suggests I want to convert a string to VK code, my original idea was to have:

HashMap<char,(what)> map= new HashMap<>();
map.put('A',KeyEvent.VK_A);

And do that for all the values then loop through the string but I don't know if anything like that is possible.

Is the best way just to have a switch for every character?

Upvotes: 1

Views: 59

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198211

The VK constants appear to be ints, so you should just have a Map<Character, Integer>.

Alternately, you could use getExtendedKeyCodeForChar, passing in the char, to get the key code.

Upvotes: 2

Related Questions