Package org.epic.perleditor.editors

Source Code of org.epic.perleditor.editors.Mouse

package org.epic.perleditor.editors;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;

/**
* Supports emulation of moving the mouse pointer and clicking.
*/
public class Mouse
{
    public static void click(Point p, boolean rightClick)
    {
        // display.post doesn't work (under Linux?)
       
        Display display = Display.getDefault();
       
        try
        {
            int button =
                rightClick ? InputEvent.BUTTON3_MASK : InputEvent.BUTTON1_MASK;
           
            Robot robot = new Robot();
            robot.mouseMove(p.x, p.y);
            while (display.readAndDispatch());
            try { Thread.sleep(20); } catch (InterruptedException _) { }
            robot.mousePress(button);
            while (display.readAndDispatch());
            try { Thread.sleep(20); } catch (InterruptedException _) { }
            robot.mouseRelease(button);
            while (display.readAndDispatch());
            try { Thread.sleep(20); } catch (InterruptedException _) { }
        }
        catch (AWTException e) { throw new RuntimeException(e); }
    }
}
TOP

Related Classes of org.epic.perleditor.editors.Mouse

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.