I too was using KeyPressEvent in 2.0.4 and it was working perfectly but when I upgraded to 2.1.1 it stopped working. Based on Brian Reilly's comment I changed the event to KeyDownHandler and the comparison to event.getNativeKeyCode() == RETURN_KEY and it's back to working again. So even though the workaround worked, I do believe that this is a bug since it used to work in 2.0.4.
On Dec 3, 6:38 am, Brian Reilly <[email protected]> wrote: > I fiddled with this quite a bit a while back, and I just upgraded to 2.1 so > I panicked when I read this. However, I just tested in Safari and Firefox > (both on Mac) and everything still works. > > The key, as Dominic mentioned, is to handle KEY_ENTER in a handler for > KeyDownEvent instead of KeyPressEvent. Actually, I also just noticed that > I'm not using event.getCharCode(). I'm > using event.getNativeEvent().getKeyCode(). In fact, looking at the JavaDoc > for KeyCode, it says, "Contains the native key codes ...", so that gives me > some confidence that getting the key code from the native event is the way > to go. > > I suspect that it's the combination of using KeyDownEvent > and event.getNativeEvent().getKeyCode(). Character codes are probably more > to represent printable characters. While you could consider a new line a > printable character, the enter key doesn't translate to a new line in all > input contexts. I suspect you're in one of those contexts (if you're trying > to add some behavior for it), so it makes sense that you want the native > event in this case instead of whatever character it would be interpreted as. > > -Brian > > On Fri, Dec 3, 2010 at 7:57 AM, aditya sanas <[email protected]>wrote: > > > hi dominic, > > > I m receiving key press event in all the browser the thing that i have > > noticed which doesn't work in GWT 2.1 is - > > > *if(event.getCharCode()==KeyCodes.KEY_ENTER){ * > > > the o/p of event.getCharCode() in GWT 2.1 is nothing not even 0 so i cnt > > compare it with KeyCodes.KEY_ENTER > > > i had tried one more new method that has been introduced in GWT 2.1 which > > getUnicodeCode() which gives 0 whenever i presses ENTER but this is not the > > right because i m getting 0 even when i m pressing any arrow key. > > > how to figure this out...? > > > -- > > Aditya > > > On Fri, Dec 3, 2010 at 5:46 PM, dominic jansen > > <[email protected]>wrote: > > >> hi aditya, > > >> i ve noticed that there are different behaviours for the > >> KeyPressHandler for each browser (e.g. for me the safari browser did > >> not recognize the keypressevent). > > >> maybe you can use the KeyDownHandler or KeyUpHandler instead of the > >> KeyPressHandler. this worked for me.... > > >> best, dom > > >> 2010/12/3 Aditya <[email protected]>: > >> > Hi, > > >> > I have updated my GWT version to 2.1 and faced some of the problems > >> > regarding textbox' key press handlers... > > >> > the code which works completely fine in previous version is > > >> > txtPassword.addKeyPressHandler(new > >> > KeyPressHandler() { > >> > @Override > >> > public void onKeyPress(KeyPressEvent event) { > > >> if(event.getCharCode()==KeyCodes.KEY_ENTER){ > >> > // some processing here to send > >> > username password to server > >> > } > >> > // class closures. > > >> > whenever user presses an ENTER key the code from 'if' condition gets > >> > executed but this does nt work in GWT 2.1 > >> > is there any other way to perform this validation to know user has > >> > striked ENTER or not...? > > >> > Thanks, > >> > Aditya > > >> > -- > >> > 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]<google-web-toolkit%[email protected]> > >> . > >> > For more options, visit this group at > >>http://groups.google.com/group/google-web-toolkit?hl=en. > > >> -- > >> 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]<google-web-toolkit%[email protected]> > >> . > >> For more options, visit this group at > >>http://groups.google.com/group/google-web-toolkit?hl=en. > > > -- > > 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]<google-web-toolkit%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-web-toolkit?hl=en. > > -- 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.
