In a method i'm receiving vk_key
's as just a int
, nothing more is provided.
I need to forward this, which looks like:
parent.postEvent(new KeyEvent(null, parent.millis(), KeyEvent.TYPE, modiefiers, c_key, vk_key));
The problem is there are also things like VK_UP
, VK_DOWN
etc.
Where normally I need to do a cast: char c_key = (char)vk_key;
, this is incorrect for VK_UP
etc. cause the cast will make the up key a '&' for example.
For those cases the c_key should be set to KeyEvent.CHAR_UNDEFINED
.
What I do now is this:
switch (vk_key) {
case VK_UP:
case VK_LEFT:
case VK_RIGHT:
case VK_DOWN:
c_key = CHAR_UNDEFINED;
break;
}
But this does not feel like the right way to do it.
Ideally there would have been a static method like static public char getCharForKey(int vk_key)
, which would return CHAR_UNDEFINED
where required. But as always oracle makes things way harder then they should be.
So is there any easy way to figure out if something should be CHAR_UNDEFINED
or not?