Thursday, May 28, 2009

A Swing component to display last keystroke and keystroke history

A Swing component to display last keystroke. Also shows the keystroke history.

How it works

The KeyLabel component registers a global listener for KeyEvents using:
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
On receiving KEY_RELEASED event formats the KeyStroke as a string and displays it. The dropdown shows history of last 100 keystrokes. Clicking on the X (Clear KeyStroke History) button clears the keystroke history. The KeyEvent listening can be suspended by deseleting the checkbox.

JComponent keyLabel = KeyLabelFactory.createKeyLabel();
// Use keyLabel in your application's statusbar

Download (KeyLabel.jar)
> java -jar KeyLabel.jar
Screenshot of KeyLabel Demo

Source Code

No comments: