Catching TAB via KeyEvent?
I thought it'd be simple, but apparently not... Wanted to catch the TAB key in one of my Java programs, and added a KeyListener to do the job. The problem is... it catches every single key other than TAB. I've used both KeyPressed, KeyReleased and KeyTyped, but none of them trigger on TAB. Is there a secret to catching TAB, or is it something very weird on my end? The code (as simple as can be, so not sure you even need it):
Code:
head.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent ke)
{
System.out.println("Key released: "+ke);
}
public void keyTyped(KeyEvent ke)
{
System.out.println("Key typed: "+ke);
}
public void keyPressed(KeyEvent ke)
{
System.out.println("Key pressed: "+ke);
}
}
);
Here's the output for pressing "a":
Code:
Key pressed: java.awt.event.KeyEvent[KEY_PRESSED,keyCode=65,keyText=A,keyChar='a',keyLocation=KEY_LOCATION_STANDARD,rawCode=65,primaryLevelUnicode=97,scancode=30] on frame0
Key typed: java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyText=Unknown keyCode:0x0,keyChar='a',keyLocation=KEY_LOCATION_UNKNOWN,rawCode=0,primaryLevelUnicode=0,scancode=0] on frame0
Key released: java.awt.event.KeyEvent[KEY_RELEASED,keyCode=65,keyText=A,keyChar='a',keyLocation=KEY_LOCATION_STANDARD,rawCode=65,primaryLevelUnicode=97,scancode=30] on frame0