Java AWT KeyEvent get key code text
import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import javax.swing.JTextField; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Window Title"); frame.setBounds(50, 100, 300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField typingArea = new JTextField(20); typingArea.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { displayInfo(e, "KEY TYPED: "); }//from ww w . ja v a2 s .c om public void keyPressed(KeyEvent e) { displayInfo(e, "KEY PRESSED: "); } public void keyReleased(KeyEvent e) { displayInfo(e, "KEY RELEASED: "); } protected void displayInfo(KeyEvent e, String s) { int id = e.getID(); if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); System.out.println("key character = '" + c + "'"); } else { int keyCode = e.getKeyCode(); System.out.println("key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"); } } }); frame.add(typingArea); frame.setVisible(true); } }