while (isKeyboardReaderRunning()) {
Object event = readKey();
// identify the kind of event (key, mouse)
int key = -1;
MouseEvent mouseEvent = null;
if(event == null)
break;
else if(event instanceof Integer)
key = ((Integer) event).intValue();
else if(event instanceof MouseEvent)
mouseEvent = (MouseEvent) event;
if(mouseEvent != null)
{
fireMouseEvent(mouseEvent);
}
/* Note that if the "kent" key is defined, ncurses returns
* VK_ENTER when the ENTER key is pressed; but some terminfo
* files don't define the "kent" capability.
*/
else if (key == '\n' || key == '\r')
key = KeyEvent.VK_ENTER;
/* Likewise, some versions of curses don't map '\b' to
* VK_BACK_SPACE (Solaris at least); this works around
* that. (I can't imagine anyone wanting \b to be mapped
* to anything else. If they do, then they should set it
* up that way in the terminfo database.)
*/
else if (key == '\b')
{
key = KeyEvent.VK_BACK_SPACE;
}
else
{
fireKeystroke(key);
}
/* If script recording is on.
*/
if (_scriptPrintStream != null) {
scriptbuf.setLength(0);
/* Compute the elapsed time since the last keystroke.
*/
long current = System.currentTimeMillis();
long elapsed = 1000; // initial delay of 1 sec
if (_prevTimeMillis != 0)
elapsed = current - _prevTimeMillis;
_prevTimeMillis = current;
scriptbuf.append(elapsed).append(" ");
if (mouseEvent != null) {
scriptbuf.append("MOUSE ").
append(mouseEvent.getX()).
append(" ").
append(mouseEvent.getY());
} else {
scriptbuf.append("KEY ");
scriptbuf.append(Integer.toHexString(key));
scriptbuf.append(" ");
scriptbuf.append(key2ASCII(key));