Search code examples
javacharkeylistenerkeyevent

Missing Character For KeyEvent


When using the KeyTyped method for the KeyListener, sometimes I get "missing characters". I'll show the code I use to get them, then ask my question.

public class KeyInput implements KeyListener
{
     public void keyTyped(KeyEvent e)
     {
         System.out.println(e.getKeyChar());
     }
}

I left out a few required methods because they are unrelated to my question. If I press a letter, it prints the letter to console. But if I use a key combination, ie. control + g, The character printed to console is just a square with a question mark.

enter image description here

Is there a way to detect if the character is a "missing character"?


Solution

  • Maybe you can use the canDisplay(...) method of the Font class.