public void onKeyPress(KeyPressEvent event) {

        Widget widget = (Widget)event.getSource();
        int unicodeCharCode = event.getUnicodeCharCode();
        char keyCode = event.getCharCode();

        if (widget == m_tbHexColor) {
            // Disallow non-hex in hexadecimal boxes
            if ((!Character.isDigit(keyCode))
                && (unicodeCharCode != 'A')
                && (unicodeCharCode != 'a')
                && (unicodeCharCode != 'B')
                && (unicodeCharCode != 'b')
                && (unicodeCharCode != 'C')
                && (unicodeCharCode != 'c')
                && (unicodeCharCode != 'D')
                && (unicodeCharCode != 'd')
                && (unicodeCharCode != 'E')
                && (unicodeCharCode != 'e')
                && (unicodeCharCode != 'F')
                && (unicodeCharCode != 'f')
                && (unicodeCharCode != KeyCodes.KEY_TAB)
                && (unicodeCharCode != (char)KeyCodes.KEY_BACKSPACE)
                && (unicodeCharCode != (char)KeyCodes.KEY_DELETE)
                && (unicodeCharCode != (char)KeyCodes.KEY_ENTER)
                && (unicodeCharCode != (char)KeyCodes.KEY_HOME)
                && (unicodeCharCode != (char)KeyCodes.KEY_END)
                && (unicodeCharCode != (char)KeyCodes.KEY_LEFT)
                && (unicodeCharCode != (char)KeyCodes.KEY_UP)
                && (unicodeCharCode != (char)KeyCodes.KEY_RIGHT)
                && (unicodeCharCode != (char)KeyCodes.KEY_DOWN)) {
                ((TextBox)widget).cancelKey();
            }
        } else {
            // Disallow non-numerics in numeric boxes
            if ((!Character.isDigit(keyCode))
                && (keyCode != (char)KeyCodes.KEY_TAB)
                && (keyCode != (char)KeyCodes.KEY_BACKSPACE)
                && (keyCode != (char)KeyCodes.KEY_DELETE)
                && (keyCode != (char)KeyCodes.KEY_ENTER)
                && (keyCode != (char)KeyCodes.KEY_HOME)
                && (keyCode != (char)KeyCodes.KEY_END)
                && (keyCode != (char)KeyCodes.KEY_LEFT)
                && (keyCode != (char)KeyCodes.KEY_UP)
                && (keyCode != (char)KeyCodes.KEY_RIGHT)
                && (keyCode != (char)KeyCodes.KEY_DOWN)) {
                ((TextBox)widget).cancelKey();
            }
        }
    }
public void onKeyPress ( KeyPressEvent event ) { Widget widget = ( Widget ) event . getSource ( ) ; int unicodeCharCode = event . getUnicodeCharCode ( ) ; char keyCode = event . getCharCode ( ) ; if ( widget == m_tbHexColor ) { if ( ( ! Character . isDigit ( keyCode ) ) && ( unicodeCharCode != 'A' ) && ( unicodeCharCode != 'a' ) && ( unicodeCharCode != 'B' ) && ( unicodeCharCode != 'b' ) && ( unicodeCharCode != 'C' ) && ( unicodeCharCode != 'c' ) && ( unicodeCharCode != 'D' ) && ( unicodeCharCode != 'd' ) && ( unicodeCharCode != 'E' ) && ( unicodeCharCode != 'e' ) && ( unicodeCharCode != 'F' ) && ( unicodeCharCode != 'f' ) && ( unicodeCharCode != KeyCodes . KEY_TAB ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_BACKSPACE ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_DELETE ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_ENTER ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_HOME ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_END ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_LEFT ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_UP ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_RIGHT ) && ( unicodeCharCode != ( char ) KeyCodes . KEY_DOWN ) ) { ( ( TextBox ) widget ) . cancelKey ( ) ; } } else { if ( ( ! Character . isDigit ( keyCode ) ) && ( keyCode != ( char ) KeyCodes . KEY_TAB ) && ( keyCode != ( char ) KeyCodes . KEY_BACKSPACE ) && ( keyCode != ( char ) KeyCodes . KEY_DELETE ) && ( keyCode != ( char ) KeyCodes . KEY_ENTER ) && ( keyCode != ( char ) KeyCodes . KEY_HOME ) && ( keyCode != ( char ) KeyCodes . KEY_END ) && ( keyCode != ( char ) KeyCodes . KEY_LEFT ) && ( keyCode != ( char ) KeyCodes . KEY_UP ) && ( keyCode != ( char ) KeyCodes . KEY_RIGHT ) && ( keyCode != ( char ) KeyCodes . KEY_DOWN ) ) { ( ( TextBox ) widget ) . cancelKey ( ) ; } } }
Fired when a keyboard action generates a character. This occurs after onKeyDown and onKeyUp are fired for the physical key that was pressed.<p>
It should be noted that many browsers do not generate keypress events for non-printing keyCode values.<p>
Such as KEY_ENTER or arrow keys.

@param event the widget that was focused when the event occurred.