soruce code name:   KeyDemo3.java

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

addKeyListener(this);
}
 
public void keyPressed(KeyEvent ke)
{
System.out.println("key is Pressed");
char ch=ke.getKeyChar();
Graphics g=getGraphics();
if(ch=='c' || ch=='C')
g.drawOval(100,100,30,30);

if(ch=='s' || ch=='S')
g.drawRect(100,160,30,30);

if(ch=='r' || ch=='R')
g.drawRect(100,200,130,30);

}
public void keyReleased(KeyEvent me){}
public void keyTyped(KeyEvent me){}

 public static void main(String[] args)
{  
KeyDemo3 f=new KeyDemo3();
f.setTitle("Key Event program");
f.setSize(400,500);  
 f.setVisible(true);  
    }
}  

output: