Java by API/java.awt/Robot
Содержание
Robot: createScreenCapture(Rectangle screenRect)
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
public class Main {
public static void main(String[] argv) throws Exception {
Robot robot = new Robot();
int x = 100;
int y = 100;
int width = 200;
int height = 200;
Rectangle area = new Rectangle(x, y, width, height);
BufferedImage bufferedImage = robot.createScreenCapture(area);
// Capture the whole screen
area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
bufferedImage = robot.createScreenCapture(area);
}
}
Robot: getPixelColor(int x, int y)
import java.awt.Color;
import java.awt.Robot;
public class Main {
public static void main(String[] args) throws Exception{
Robot robot = new Robot();
Color color = robot.getPixelColor(20, 20);
System.out.println("Red = " + color.getRed());
System.out.println("Green = " + color.getGreen());
System.out.println("Blue = " + color.getBlue());
}
}
Robot: keyPress(int keycode)
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Main {
public static void main(String[] argv) throws Exception {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
}
}
Robot: keyRelease(int keycode)
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Main {
public static void main(String[] argv) throws Exception {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
}
}
Robot: mouseMove(int x, int y)
import java.awt.Robot;
import java.awt.event.InputEvent;
public class MainClass {
public static void main(String[] args) throws Exception{
Robot r = new Robot();
r.mouseMove(35,35);
r.mousePress( InputEvent.BUTTON1_MASK );
r.mouseRelease( InputEvent.BUTTON1_MASK );
Thread.sleep(50);
r.mousePress( InputEvent.BUTTON1_MASK );
r.mouseRelease( InputEvent.BUTTON1_MASK );
}
}
Robot: mousePress(int buttons)
import java.awt.Robot;
import java.awt.event.InputEvent;
public class MainClass {
public static void main(String[] args) throws Exception{
Robot r = new Robot();
r.mouseMove(35,35);
r.mousePress( InputEvent.BUTTON1_MASK );
r.mouseRelease( InputEvent.BUTTON1_MASK );
Thread.sleep(50);
r.mousePress( InputEvent.BUTTON1_MASK );
r.mouseRelease( InputEvent.BUTTON1_MASK );
}
}
Robot: mouseRelease(int buttons)
import java.awt.Robot;
import java.awt.event.InputEvent;
public class MainClass {
public static void main(String[] args) throws Exception{
Robot r = new Robot();
r.mouseMove(35,35);
r.mousePress( InputEvent.BUTTON1_MASK );
r.mouseRelease( InputEvent.BUTTON1_MASK );
Thread.sleep(50);
r.mousePress( InputEvent.BUTTON1_MASK );
r.mouseRelease( InputEvent.BUTTON1_MASK );
}
}
Robot: mouseWheel(int wheelAmt)
import java.awt.Robot;
import java.awt.event.InputEvent;
public class Main {
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.mouseMove(200, 200);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseWheel(-100);
}
}