Mozilla DialogBox.onKeyPressPreview() broken in 1.1?

16 views
Skip to first unread message

lpod...@gmail.com

unread,
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
hide();
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

unread,
Aug 14, 2006, 7:49:25 PM8/14/06
to Google-We...@googlegroups.com
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
evt.which.

You can see which keycodes are available for which events here:
http://www.asquare.net/javascript/tests/KeyCode.html

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
http://www.asquare.net

Reply all
Reply to author
Forward
0 new messages