!7 static int windowSize = 11; // odd should look nice. Set to 1 for an invisible window static int clickDelay = 0; // Delay in ms between closing window and forwarding click. 0 seems to work fine. static int trackingSpeed = 10; // How often to move the window (ms) p { final new JWindow window; window.setSize(windowSize, windowSize); window.setVisible(true); window.setAlwaysOnTop(true); JPanel panel = singleColorPanel(Color.red); window.setContentPane(panel); revalidate(window); final new Robot robot; panel.addMouseListener(new MouseAdapter { // public void mousePressed(final MouseEvent e) {} public void mouseReleased(final MouseEvent e) { print("release! " + e); window.setVisible(false); int b = e.getButton(); final int mod = b == 1 ? InputEvent.BUTTON1_DOWN_MASK : b == 2 ? InputEvent.BUTTON2_DOWN_MASK : InputEvent.BUTTON3_DOWN_MASK; swingLater(clickDelay, r { print("clicking " + mod); robot.mousePress(mod); robot.mouseRelease(mod); }); } }); swingEvery(window, trackingSpeed, r { Point p = getMouseLocation(); window.setLocation(p.x-windowSize/2, p.y-windowSize/2); //print("moving"); }); }