Mozilla DialogBox.onKeyPressPreview() broken in 1.1?

Skip to first unread message

Aug 14, 2006, 5:09:23 PM8/14/06
to Google Web Toolkit
I have code like the following in a DialogBox subclass that dismisses a
dialog box when the user presses the Escape key:

public boolean onKeyPressPreview(char key, int modifiers) {
if (key == 033) { // ESC
return false;
return true; // propagate event

This code worked in all browsers in 1.0.21. In 1.1, it still works in
hosted mode and in IE, but does not work in Firefox. Looking more
closely, the reason is that in Firefox the value of key is 0 when
Escape is pressed. Interestingly, the value is not always 0 -- most
key codes get sent correctly, but so far I've seen that ESC and tab
result in key being 0. Is this a known issue? As I mentioned, this
worked fine in 1.0.21.

Mat Gessel

Aug 14, 2006, 7:49:25 PM8/14/06
Looks like a side-effect of the DOM.eventGetKeyCode() fix. In 1.1, IE
still reads evt.keyCode, but the other browsers were changed to read

You can see which keycodes are available for which events here:

To trap non-character keys I'd use the keydown or keyup methods. The
alpha keycodes returned in keydown and keyup are usually capitalized
so I do a Character.toUpperCase((char) keycode) when I need to compare
to them.

Mat Gessel

Reply all
Reply to author
0 new messages