source code name: KeyDemo2.java

    import java.awt.*;
 
    import java.awt.event.*;
 class KeyDemo2 extends Frame implements KeyListener
{
 public KeyDemo2()

addKeyListener(this);
}
 
public void keyPressed(KeyEvent ke)
{
System.out.println("key is Pressed");
char ch=ke.getKeyChar();
int n=ke.getKeyCode();
String txt=ke.getKeyText(n);
System.out.println("character: "+ch+" ascii code: "+n+" text on key: "+txt);
}
public void keyReleased(KeyEvent me){}
public void keyTyped(KeyEvent me){}

 public static void main(String[] args)

KeyDemo2 f=new KeyDemo2();
f.setTitle("Key Event program");
f.setSize(400,500); 
 f.setVisible(true); 
    }
}  

output: