KeyEvent クラス

import java.awt.*;
import java.awt.event.*;

public class Test {
	public static void main (String[] args)
	{
		Win win = new Win("Test Window", "Test Data");
	}
}

/*******************/
/* クラスWinの定義 */
/*******************/
class Win extends Frame implements KeyListener {

	TextArea tx1, tx2;

	/******************/
	/* コンストラクタ */
	/******************/
	Win (String name, String data)
	{
					// Frameクラスのコンストラクタ(Windowのタイトルを引き渡す)
		super(name);
					// レイアウトの変更(行,列,水平ギャップ,垂直ギャップ)
		setLayout(new GridLayout(2, 1, 5, 10));
		Font f = new Font("MS 明朝", Font.PLAIN, 20);
					// テキストエリアの追加
		tx1 = new TextArea(4, 23);
		tx1.setFont(f);
		tx1.addKeyListener(this);
		add(tx1);

		tx2 = new TextArea(5, 23);
		tx2.setFont(f);
		add(tx2);
					// Windowの大きさ
		setSize(300, 450);
					// ウィンドウを表示
		setVisible(true);
					// イベントアダプタ
		addWindowListener(new WinEnd());
	}

	/******************************/
	/* 上,左,下,右の余白の設定 */
	/******************************/
	public Insets getInsets()
	{
		return new Insets(35, 10, 10, 10);
	}

	/*************************/
	/* KeyListenerによる処理 */
	/*************************/
	public void keyPressed(KeyEvent e) {}
	public void keyReleased(KeyEvent e)
	{
		tx2.append("Release : ");
		String str = e.getKeyModifiersText(e.getModifiers());
		if (str.length() > 0)
			tx2.append(str + " + ");
		tx2.append(e.getKeyText(e.getKeyCode()) + "\n");
	}
	public void keyTyped(KeyEvent e)
	{
		tx2.append("Type : ");
		String str = e.getKeyModifiersText(e.getModifiers());
		if (str.length() > 0)
			tx2.append(str + " + ");
		tx2.append(e.getKeyChar() + "\n");
	}

	/************/
	/* 終了処理 */
	/************/
	class WinEnd extends WindowAdapter
	{
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	}
}