Java控制鼠标/键盘动作示例 ①

14年前
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();    }   }  }