I'm trying to perform an action when the 'tilde key' is pressed on my keyboard it looks like �� on top of each other.
I first tried KeyEvent.VK_DEAD_TILDE but it is not generated.
When I run this demo on this page:
http://www.dil.univ-mrs.fr/~garreta/docJava/tutorial/uiswing/events/keylistener.html
http://java.sun.com/docs/books/tutorialJWS/uiswing/events/examples/KeyEventDemo.jnlp
then I get:
KEY PRESSED:
key code = 0 (Unknown keyCode: 0x0)
extended modifiers = 0 (no extended modifiers)
action key? NO
key location: standard
KEY TYPED:
key character = '�'
extended modifiers = 0 (no extended modifiers)
action key? NO
key location: unknown
KEY RELEASED:
key code = 0 (Unknown keyCode: 0x0)
extended modifiers = 0 (no extended modifiers)
action key? NO
key location: standard
My test code:
public class Test implements KeyListener {
public Test() {
JFrame frame = new JFrame();
frame.setSize(150, 200);
frame.setVisible(true);
frame.addKeyListener(this);
}
public void keyTyped(KeyEvent e) {
System.out.println(e.getKeyCode());
if (e.getKeyCode() == KeyEvent.VK_DEAD_TILDE) {
System.out.println("hooray");
} else {
System.out.println("nope");
}
}
public void keyPressed(KeyEvent e) {
System.out.println(e.getKeyCode());
if (e.getKeyCode() == KeyEvent.VK_DEAD_TILDE) {
System.out.println("hooray");
} else {
System.out.println("nope");
}
}
public void keyReleased(KeyEvent e) {
}
public static void main(String[] args) {
new Test();
}
}
How can I capture the tilde key being pressed?