Question

I'm trying to test by SWTBot hyperlinks inside my Eclipse's text editor. The problem is that the hyperlinks are shown on demand (an Eclipse feature), meaning - the token changes is revealed as hyperLink only when mouse moves over it + a keyboard key (Ctrl or Alt) is pressed.

How can I simulate in SWTBot the mouse-move together with a key pressed?

No correct solution

OTHER TIPS

When mouse moves over a link, then a MouseEvent is generated. Some MouseMotionListener (or maybe MouseListener) consumes this event and then shows hiperlink for you. You can simulate this event:

Component source = null; // TODO set up a valid component
    MouseEvent event = new MouseEvent(source, MouseEvent.MOUSE_ENTERED, System.currentTimeMillis(), InputEvent.ALT_DOWN_MASK, source.getX(), source.getY(), 0, false);
    MouseMotionListener[] mouseMotionListeners = source.getMouseMotionListeners();
    if (mouseMotionListeners!= null && mouseMotionListeners.length > 0) {
        MouseMotionListener mouseMotionListener = mouseMotionListeners[0];
        mouseMotionListener.mouseMoved(event);
    }

The InputEvent.ALT_DOWN_MASK in the constructor means that Alt is pressed. Note that you should define what Component responsible for consuming events in your case.

You can find more information in the tutorial How to Write a Mouse Listener and MouseEvent API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top