Tracking mouse movements over a page using GWT

In the GWT application, I would like to track and display the X, Y mouse coordinates and intercept clicks throughout the browser page. The page contains many GWT widgets, such as panels, buttons, etc. Any advice would be appreciated.

Thanks. Daniel

+5
source share
2 answers

I had to use them a couple of times recently for various reasons. This is a very simple example of how to use the GWT preview material.

, : onPreviewNativeEvent() .... . - , , IE / . , .

Event.addNativePreviewHandler(new NativePreviewHandler() {
  public void onPreviewNativeEvent(final NativePreviewEvent event) {
    final int eventType = event.getTypeInt();
    switch (eventType) {
      case Event.ONMOUSEMOVE:
        //mouse tracking logic?
        break;
      case Event.ONCLICK:
        final int eventX = event.getNativeEvent().getClientX();
        final int eventY = event.getNativeEvent().getClientY();
        Window.alert("Clicked @ " + eventX + "," + eventY);
        break;
      default:
        // not interested in other events
    }
  }
});
+6

All Articles