Hi Thomas, Sorry about the delay in responding to this. I just wanted to follow up on this point:
> Firefox only adds KeyPress events. The issue is Opera here, and *only* Opera. If that was true, I would tend to agree with you. In my testing, Opera is almost always the problem child. But if you have access to a Mac, try that test in Firefox. On the Mac, Firefox fires *only* keypress for key-repeat of special characters: Go to http://unixpapa.com/js/testkey.html and press down-arrow long enough to trigger a few key-repeats. Chrome 5.0.322.2: keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=3 shiftKey=false ctrlKey=false altKey=false metaKey=false keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=3 shiftKey=false ctrlKey=false altKey=false metaKey=false keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=3 shiftKey=false ctrlKey=false altKey=false metaKey=false keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=3 shiftKey=false ctrlKey=false altKey=false metaKey=false keyup keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=3 shiftKey=false ctrlKey=false altKey=false metaKey=false Firefox 3.6: keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=undefined keyLocation=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false keypress keyCode=40 (() which=0 charCode=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keypress keyCode=40 (() which=0 charCode=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keypress keyCode=40 (() which=0 charCode=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keyup keyCode=40 (() which=40 (() charCode=0 keyIdentifier=undefined keyLocation=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false Opera 10.10: keydown keyCode=40 (() which=40 (() charCode=undefined keyIdentifier=undefined keyLocation=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false keypress keyCode=40 (() which=0 charCode=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false keypress keyCode=40 (() which=0 charCode=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false keypress keyCode=40 (() which=0 charCode=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false keyup keyCode=40 (() which=40 (() charCode=undefined keyIdentifier=undefined keyLocation=undefined shiftKey=false ctrlKey=false altKey=false metaKey=false Safari 4.0.4: keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keydown keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=0 shiftKey=false ctrlKey=false altKey=false metaKey=false keyup keyCode=40 (() which=40 (() charCode=0 keyIdentifier=Down keyLocation=0 shiftKey=false ctrlKey=false altKey=false metaKey=false On Feb 15, 6:31 am, Thomas Broyer <[email protected]> wrote: > On Feb 14, 7:31 pm, Jim Douglas <[email protected]> wrote: > > > Thomas, > > > Alan is writing low level code that needs to deal correctly with key > > repeats in all browsers. > > OK, sorry. The real issue is with repeats then, and more specifically > Opera. But Alan titled his message "get keycode from KeyDownHandler, > KeyUpHandler" and talks about IE; and there I see absolutely no issue > at all. > > > Sadly, this requires writing browser- > > specific code that does some detailed parsing of the keydown and > > keypress events. > > Only in Opera actually, because it only repeats KeyPress events > (whereas it shouldn't even fire them in the first place in case of > arrow keys which do not generate text) > > > This article provides some good background: > > >http://unixpapa.com/js/key.html > > > And the associated test page is a convenient way to see what events a > > browser fires for each key: > > >http://unixpapa.com/js/testkey.html > > > One simple example: > > > Open that page in Firefox. > > Press the right arrow key long enough to trigger key-repeat. > > Note the stream of events. > > Do the same in Chrome; note the different stream of events. > > Firefox only adds KeyPress events. The issue is Opera here, and *only* > Opera. > > > PPK's notes are out of date, but still useful: > > >http://www.quirksmode.org/js/keys.html > > They do not deal with repeats. > > > Bottom line: Writing low level JavaScript code to manage keystrokes > > is a challenge. The GWT documentation notes that there are no > > coherent browser standards in this area: > > >http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/g... > > "The native keyboard events are somewhat a mess > > (http://www.quirksmode.org/js/keys.html), we do some trivial normalization > > here, but do not attempt any complex patching, so user be warned." > > See:http://code.google.com/p/google-web-toolkit/issues/detail?id=3753http://groups.google.fr/group/Google-Web-Toolkit-Contributors/t/e7059... > andhttp://gwt-code-reviews.appspot.com/142801/show > > So, as I said, the only issue here is Opera (Firefox behavior is a > PITA too, but workable). So, either: > - do yourself a favor, don't support repeats in Opera (they'll > probably change behavior sooner or later given that DOM3EVENTS lead > towards IE/Safari behavior [1]) > - use deferred binding to special-case Opera (store > KeyDownEvent::getNativeKeyCode and check repeats in KeyPress *instead* > of KeyDown while KeyPressEvent::getCharCode() == > KeyDownEvent::getNativeKeyCode(); because in current GWT versions, > KeyPressEvent::getCharCode will give you the arrow "codes", in both > Opera and Firefox BTW); which would be an almost equivalent to the > code you proposed, just far simpler: > > private int keyCode; > > public void onKeyDown(KeyDownEvent event) { > keyCode = event.getNativeKeyCode(); > // given that registering/unregistering event handlers in Opera is > very fast > // you could even only register the KeyPressHandler when keyCode > needs > // repeats-processing! > > } > > public void onKeyPress(KeyPressEvent event) { > if (keyCode == event.getCharCode()) { > // process this keypress as if it were a keydown in other > browsers > } > > } > > It of course becomes more complex if you also have to deal with keys > that are *expected* to generate keypress (I assume IE/Safari behavior > here). > > [1]http://www.w3.org/TR/DOM-Level-3-Events/ -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
