Search code examples
javahashmapvirtual-keyboard

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?


Solution

  • 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.