Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to trap a keyboard event in GWT?

Tags:

gwt

I'm trying to trap key downs in GWT, and I've tried both addKeyDownHandler and onBrowserEvent. The problem is that they work as long as the appropriate widget had the focus, but it stops working when something else has the focus. I could add the code to every single widget, but that seems crazy. I also tried forcing one single widget to always have the focus, but that causes other problems with things like TextBoxes (which need the focus for typing).

Is there just a simple, high-level way to trigger some code when a key is pressed in GWT, regardless of which widget has the focus?

like image 879
Soren Johnson Avatar asked Feb 22 '23 19:02

Soren Johnson


1 Answers

You can use either Event.addNativePreviewHandler, or a KeyDownHandler that you'd attach to RootPanel.get() (using addDomHandler: RootPanel.get().addDomHandler(myHandler, KeyDownEvent.getType())), depending on whether you want to listen in the capture or bubble phase (the capture phase is emulated in IE).

like image 54
Thomas Broyer Avatar answered Feb 25 '23 10:02

Thomas Broyer