How do I attach an event handler to the document or window in GWT?

Posted by Raph Levien on Stack Overflow See other posts from Stack Overflow or by Raph Levien
Published on 2011-01-08T22:49:38Z Indexed on 2011/01/08 22:53 UTC
Read the original article Hit count: 203

Filed under:

In a GWT app centered around a canvas, I'm having trouble keeping focus directed in the right place - particularly for keyboard shortcuts. For now, I've wrapped the canvas in a FocusPanel, but that causes the canvas to not respond to the RequiresResize protocol, because FocusPanel does not plumb that.

A second (related, I think) problem is that the FocusPanel is not getting Ctrl-A keypress events at all (tested on Mac Chrome). I can get Ctrl-Z and other keys (such as arrows) just fine.

In a pure JavaScript world, I think the best answer to this would be to attach mouse and key handlers to the document or window object (I'm not positive which is better). However, I don't see an obvious way to do this in GWT - in particular, the Document and Window classes lack methods for attaching these kind of event handlers?

Anyone know how to do it, or, perhaps, to solve the more general problem of keeping focus on an appropriate widget able to handle keyboard shortcuts?

© Stack Overflow or respective owner

Related posts about gwt