MyTitle MyTitle - 5 months ago 21
Java Question

Determine "Backspace" button pressing

How to determine in GWT that user pressed Backspace button? I tried this, but it does not work

@Override
public void onKeyPress(KeyPressEvent event) {
char charCode= event.getCharCode();
if(charCode == (char) KeyCodes.KEY_BACKSPACE){
//do someThing
}
}

Answer

The keypress event is implemented in most browsers as only firing when a character would be produced (and that's how it's being standardized: http://www.w3.org/TR/DOM-Level-3-Events/#event-type-keypress ). Backspace obviously doesn't produce a character; you should use keydown or keyup to detect it.

Comments