combine KeyCode pressed and modifiers to get final KeyCode

16 Views Asked by At

I'm struggling to find any answrs online to this problem...

On my Italian Keyboard if I press Shift+' I get ?. In my EventListener, the KeyEvent only reports that the ' button is being pressed and that the Shift is active. From this I can deduce that the character typed is ?. On a French or American keyboard for example, this doesn't work. I'd have to make an edge case for every keyboard layout...

I'm looking for something like this:

int finalKeyCode = KeyEvent.getExtendedFinalKeyCode(e.getExtendedKeyCode(), e.getModifiersEx());

It seems intuitive to me that there would be a way to get/determine the actual final second layer code entered, from the first layer keycode and the active modifiers relative to the current keyboard layout.

Another example is Shift+F10 which is used for the ContextMenu. In the KeyEvent I get either code 525 if the keyboard has a dedicated button, or code 121 and the Shift modifier enabled which requires me just to make another if statement or switch case.

Is there a way to convert the first layer keycode in a second layer keycode using the modifiers? Do i really have to do it manually with a ton of custom ifs or switch cases? Is there a good reason for this that I'm not seeing?

Also, I know there is the e.getKeyChar() == '?' but I'm really trying to use only the keycodes as seems only intuitive to me that this should not be impossible...

0

There are 0 best solutions below