Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.patryk.program;
- import java.awt.AWTException;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.StringSelection;
- import java.awt.event.KeyEvent;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.activation.FileDataSource;
- import javax.imageio.ImageIO;
- import org.simplejavamail.email.Email;
- import org.simplejavamail.email.EmailBuilder;
- import org.simplejavamail.mailer.Mailer;
- import org.simplejavamail.mailer.config.ServerConfig;
- import org.simplejavamail.mailer.config.TransportStrategy;
- public class Program {
- static Robot robot;
- public Program() {
- try {
- robot = new Robot();
- } catch (AWTException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static void type(String characters) {
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- StringSelection stringSelection = new StringSelection(characters);
- clipboard.setContents(stringSelection, stringSelection);
- // control+V is for pasting...
- robot.keyPress(KeyEvent.VK_CONTROL);
- robot.keyPress(KeyEvent.VK_V);
- robot.keyRelease(KeyEvent.VK_V);
- robot.keyRelease(KeyEvent.VK_CONTROL);
- robot.delay(100);
- robot.keyPress(KeyEvent.VK_ENTER);
- }
- public static void desktop() {
- robot.keyPress(KeyEvent.VK_WINDOWS);
- robot.keyPress(KeyEvent.VK_D);
- robot.keyRelease(KeyEvent.VK_WINDOWS);
- robot.keyRelease(KeyEvent.VK_D);
- }
- public void startProcess() {
- try {
- Process process = new ProcessBuilder("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
- "www.google.pl").start();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public void screenCapture() {
- // pobieramy rozmiar ekranu i tworzymy Rectangle
- Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
- Rectangle rectangle = new Rectangle(dimension);
- // robimy screenshot z utworzonego obszaru
- BufferedImage screen = robot.createScreenCapture(rectangle);
- try {
- ImageIO.write(screen, "jpg", new File("screenshot.jpg"));
- } catch (IOException e) {
- System.err.println("BÅÄ d zapisu obrazu");
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- Program test = new Program();
- test.robot.delay(30);
- // test.startProcess();
- test.desktop();
- // test.type("www.google.pl");
- test.robot.delay(1000);
- test.screenCapture();
- test.robot.delay(1500);
- //
- Email email = new EmailBuilder().from("abcdefg", "abcdefg@gmail.com")
- .to("Patryk", "abcdefg@gmail.com").subject("Screen").text("screen").build();
- email.addAttachment("screenshot.jpg", new FileDataSource("screenshot.jpg"));
- new Mailer(new ServerConfig("smtp.gmail.com", 465, "abcdefg@gmail.com", "password"),
- TransportStrategy.SMTP_SSL).sendMail(email);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement