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.
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