- void keyPress(int keycode)鎸変笅緇欏畾鐨勯敭
- void keyRelease(int keycode)閲婃斁緇欏畾鐨勯敭
- void mouseMove(int x, int y)灝嗛紶鏍囨寚閽堢Щ鍔ㄥ埌緇欏畾灞忓箷鍧愭爣
- void mousePress(int buttons)鎸変笅涓涓垨澶氫釜榧犳爣鎸夐挳
- void mouseRelease(int buttons)閲婃斁涓涓垨澶氫釜榧犳爣鎸夐挳
- void mouseWheel(int wheelAmt)鍦ㄩ厤鏈夋粴杞殑榧犳爣鏃嬭漿婊氳疆
- BufferedImage createScreenCapture(Rectangle screenRect)鍒涘緩鍖呭惈浠庡睆騫曚腑璇誨彇鐨勫儚绱犵殑鍥懼儚
絎竴涓緥瀛愭槸榧犳爣妯℃嫙嫻嬭瘯錛屽湪澶氱嚎紼嬩腑姣忛殧1s闅忔満縐誨姩榧犳爣錛屼竴鍏遍殢鏈?嬈¢紶鏍囬棯鐑侊紝婧愮爜濡備笅錛?br>
/*
* MouseSimulate.java
*
* Created on 2007-5-7, 4:03:04
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package cn.edu.yutao;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.util.Random;
/**
*
* @author Aslan
*/
public class MouseSimulate implements Runnable{
private volatile boolean isRunning = false;
private Robot robot;
private Dimension dim;
private Random random;
public MouseSimulate() {
random = new Random();
dim = Toolkit.getDefaultToolkit().getScreenSize();
try{
robot = new Robot();
}catch(AWTException e){
e.printStackTrace();
}
}
public void run() {
while(isRunning){
int x = random.nextInt((int)dim.getWidth());
int y = random.nextInt((int)dim.getHeight());
System.out.println("the mouse located in (" + x + "," + y + ")");
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
public synchronized void start(){
isRunning = true;
}
public synchronized void stop(){
isRunning = false;
}
public static void main(String[] args){
MouseSimulate test = new MouseSimulate();
test.start();
System.out.println("-----------time start-------------");
Thread thread = new Thread(test);
thread.start();
try{
Thread.sleep(10000);
}catch(InterruptedException e){
e.printStackTrace();
}
test.stop();
System.out.println("-----------time stop--------------");
}
}
Robot綾葷殑鏂規硶createScreenCapture鍙互綆鍗曠殑鐢ㄤ簬鎶撳彇灞忓箷鍥劇墖錛屽彲浠ュ湪java搴旂敤紼嬪簭涓洿鎺ヨ皟鐢ㄨ鏂規硶鎶撳彇灞忓箷錛屾嫻嬭繙紼嬬數鑴戝睆騫曠姸鎬侊紝榪欓噷鍙傝冧簡java紺懼尯鐨勪緥瀛愶紝榛樿鏋勯犲嚱鏁扮敓鎴愬悗緙涓簆ng鐨勬枃浠訛紝鍙互鍦ㄧ浜屼釜鏋勯犲嚱鏁頒紶鍏ュ叾浠栧悕縐幫紝鏀寔gif鍜宩pg銆傛埅鍥劇▼搴忔簮鐮佸涓嬶細
/*
* GuiCamera.java
*
* Created on 2007-5-7, 4:18:46
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package cn.edu.yutao;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
/**
*
* @author Aslan
*/
public class GuiCamera {
private String fileName;
private final String defaultFileName = "camera";
private String format;
private final String defaultFormat = "png";
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
public GuiCamera() {
this.fileName = defaultFileName;
this.format = defaultFormat;
}
public GuiCamera(String fileName, String format) {
this.fileName = fileName;
this.format = format;
}
public void capture() throws Exception{
BufferedImage imageScreen = (new Robot()).createScreenCapture(new Rectangle((int)dim.getWidth(), (int)dim.getHeight()));
String imageName = this.fileName + "." + this.format;
File file = new File(imageName);
System.out.println("Save file " + imageName);
ImageIO.write(imageScreen, format, file);
System.out.println("Finished!!");
}
public static void main(String[] args){
GuiCamera camera = new GuiCamera("hello", "jpg");
try{
camera.capture();
}catch(Exception e){
e.printStackTrace();
}
}
}
浠ヤ笂紼嬪簭閮藉湪mac os 10.4.8涓嬫祴璇曪紝鎴浘涓?nbsp; 寰堟紓浜綖 鍑虹幇璀﹀憡鏄洜涓烘煇浜沘pi鍦╦dk6涓凡緇忔爣璁頒負搴熷純銆?br>

]]>