Java控制鼠標/鍵盤動作示例 ①

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;

public class MouseClickTest { static Display display = new Display();

public static void main(String[] args)
{
    click(640,5);
    //click(640,5);
    //display.dispose();
}

static void click(final int x, final int y)
{
    new Thread()
    {
        Event event;
        public void run()
        {
            delay(300);

            event = new Event();
            event.type = SWT.MouseMove;
            event.x = x;    //橫坐標
            event.y = y;    //縱坐標
            display.post(event);

            delay(300);

            event.type = SWT.MouseDown;
            event.button = 1;
            display.post(event);

            delay(300);

            event.type = SWT.MouseUp;
            display.post(event);
        }
    }.start();
}

static void delay(int time)
{
    try
    {
        Thread.sleep(time);
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }
}

}</pre>

 本文由用戶 灬猜想灬 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!