Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package autoclicker;
- import java.awt.AWTException;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.event.InputEvent;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class main {
- //////////////////////////////////////////////////
- //////////////////////////////////////////////////
- //Arra jó, hogy beolvassa a képet jól működik/////////////////
- public static BufferedImage megnez(String kepnev)
- {
- try
- {
- BufferedImage image = ImageIO.read(new File("C://Users//User//eclipse-workspace//autoclicker//src//"+ kepnev));
- System.out.println("Megvan a kép:" + kepnev);
- return image;
- }
- catch (IOException e)
- {
- //e.printStackTrace();
- System.out.println("Nincs meg a kép:" + kepnev);
- BufferedImage semmi = null;
- return semmi;
- }
- }
- ////////////////////////////////////////////////
- ////////////////////////////////////////////////
- //Arra jó, hogy oda kattint egy bizonyos pixcelre, jól működik
- public static void kattint(int x, int y)
- {
- Robot bot;
- try
- {
- bot = new Robot();
- bot.mouseMove(x, y); //helymegadás
- bot.mousePress( InputEvent.BUTTON1_MASK ); //lenyom
- bot.mouseRelease( InputEvent.BUTTON1_MASK ); //felenged
- System.out.println("Sikeres kattintás");
- }
- catch (AWTException e)
- {
- System.out.println("Hiba");
- }
- }
- ////////////////////////////////////////////////
- ////////////////////////////////////////////////
- //Kepernyoolvaso, arra jó, hogy megkeresi az adott képet a kijelzőn és vissza adja, hogy látja-e
- //most még nem működik
- private static boolean lathatoakepernyon(String nev )
- {
- BufferedImage bi=null;
- try
- {
- bi = ImageIO.read(new File("C://Users//User//eclipse-workspace//autoclicker//src//" + nev));
- } catch (IOException e1)
- {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- BufferedImage image = null;
- try {
- image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- for(int x = 0; x< image.getWidth();x++){
- for(int y = 0; y< image.getHeight();y++){
- boolean invalid = false;
- int k = x,l = y;
- for(int a = 0;a<bi.getWidth();a++){
- l = y;
- for(int b = 0;b<bi.getHeight();b++){
- if(bi.getRGB(a, b) != image.getRGB(k, l)){
- invalid = true;
- break;
- }
- else{
- l++;
- }
- }
- if(invalid){
- break;
- }else{
- k++;
- }
- }
- if(!invalid){
- System.out.println("Megvan a kép a képernyőn");
- return true;
- }
- }
- }
- System.out.println("Nincs a képernyőn");
- return false; //If no image is found
- }
- ////////////////////////////////////////////////
- ////////////////////////////////////////////////
- ////////////////////////////////////////////////
- ////////////////////////////////////////////////
- public static void main(String[] args)
- {
- //megnez("search.png"); //helyesnek kell lennie
- //megnez("alma.png"); //hibásnak kell lennie
- //kattint(500,200); //oda kell kattintania: 500px,200px
- lathatoakepernyon("search.png");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement