My son (aged 11) who is learning Java is going to enter a question and some code. He tells me he has not been able to find the answer to this question on the site. You will
Read about java.awt.event.KeyListener
A code should look like this:
f.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key pressed code=" + e.getKeyCode() + ", char=" + e.getKeyChar());
}
@Override
public void keyReleased(KeyEvent e) {
}
});