public short getKeyCode(KeyEvent e) {
        short key = 0;
        int letter = (int)e.getKeyChar();
        short code = (short)e.getKeyCode();

        if (letter == KeyEvent.CHAR_UNDEFINED)
            key = actionKeyCodes[code];
        else {
            if (code >= 65 && code <= 90)
                key = code;
            else if (letter == 8)
                key = BACKSPACE_KEY;
            else if (letter == 10)
                key = NEWLINE_KEY;
            else if (letter == 27)
                key = ESC_KEY;
            else if (letter == 127)
                key = DELETE_KEY;
            else
                key = (short)letter;
        }

        return key;
    }