Bot erkennt Bildschirm nicht mehr korrekt

SnowCarpet

Mitglied
Hallo zusammen

Ich habe gestern schnell einen kleinen Java-Bot geschrieben, der in einem zufällig begrenzten Rhytmus einige Mausklicks ausführt.
Gestern hab ich ihn zuerst einige Mal aus Intellij direkt laufen lassen und später als eigene Programmverknüpfung und alles hat prima funktioniert.

Nun heute wollte ich ihn erneut laufen lassen, jedoch führt er die Bewegungen und Klicks nur im linken oberen Viertel des Bildschirmes aus. Die "Koordinaten" habe ich nun mit dem selben Tool wie gestern überprüft (sxCoordinateDesktop) und es hat sich nichts geändert.

Was habe ich versucht:
-Neustart
-Ausführen des Programm über Verlinkung
-Ausführen des Programm über Intellij
-neues Projekt mit Copy+Paste des Code und abändern des Klassennamens

Alles ohne Erfolg. An was könnte das liegen?

Java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.Random;

public class Skinerrep {
    public static double getRandom(){
        boolean big = false;
        double zufall = 0;
        while (!big) {
            Random r = new Random();
            zufall = r.nextDouble();
            zufall = zufall * 3000000;
            big = 1250000 < zufall && zufall < 1440000;
        }
        return zufall;
    }
  /*  public static int getOption() {
        Object[] options = {"Weiterausführen", "Beenden"};
        int wahl = JOptionPane.showOptionDialog(null, "Tickets eingesammelt.", "Skiner", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        return wahl;
    } */

    public static void main(String[] args) throws IOException, AWTException, InterruptedException{
        final Robot skin = new Robot();
        boolean timer = true;
        while(timer) {
            skin.mouseMove(180, 848);
            skin.delay(2000);
            skin.mouseMove(180, 798);
            skin.delay(2000);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(126, 25);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(1525, 120);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(500);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(1525, 424);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(302, 640);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
         /*   int wahl = getOption();
            if(wahl!=0){
                timer=false;
            }
            */
            double dwaitTime = getRandom();
            long waitTime = (new Double(dwaitTime)).longValue();
            System.out.print(waitTime);
            Thread.sleep(waitTime);

        }
    }
}



Danke im Voraus für eure Hilfe.
 

SnowCarpet

Mitglied
Hab nun ein wenig rumgetestet und fand heraus, dass beim Anschliessen meines 2. Bildschirmes wohl irgendwelche Änderung an der Auflösung meines Laptop vorgenommen wurden. Leider konnte ich trotz zig Versuchen die ursprünglichen Lage nicht rekonstruieren. Versuche nun den Code so umzuschreiben, damit er die ScreenSize erkennt und anschliessend das Programm selber die Koordinaten berechnet, da es ja prozentual immer die Gleichen sind.

Sobald ich fertig gebastelt habe, stelle ich mal den Code rein, falls eine andere verzweifelte Seele mal auf dieses Problem stossen sollte ;D.
 

SnowCarpet

Mitglied
Anbei der neue Code. Der Bot verliert ein kleines bisschen an Genauigkeit (double to int) reicht aber für meine Zwecke und funktioniert wunderbar.

Java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.IntSummaryStatistics;
import java.util.Random;

public class Coordinates {
    double x, y;
}

public class Pointer {
    Coordinates pt[];
}


public class skinermain {

    public static double getRandom() {
        boolean big = false;
        double zufall = 0;
        while (!big) {
            Random r = new Random();
            zufall = r.nextDouble();
            zufall = zufall * 3000000;
            big = 1250000 < zufall && zufall < 1440000;
        }
        return zufall;
    }
    public static double getXCoordinates(double xfactor, double x){
        double xNew = x * xfactor;
        return xNew;
    }
    public static double getYCoordinates(double yfactor, double y){
        double yNew = y * yfactor;
        return yNew;
    }


    public static void main(String[] args) throws IOException, AWTException, InterruptedException {
        final Robot skin = new Robot();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        double y = dim.getHeight();
        double x = dim.getWidth();

        //Testzwecke/ Console Output
        System.out.println("Höhe " + y + " Breite " + x);

        double[] xStandard = {181,182,86,1920,1920,471};
        double[] yStandard = {1063,1005,21,124,567,445};
        double xFactor = x / 1920;
        double yFactor = y / 1080;
        int[] xNew = new int[6];
        int[] yNew = new int[6];

        Pointer mouse = new Pointer();
        mouse.pt = new Coordinates[6];
        //neue Koordinaten berechnen und zuweisen
        for(int i = 0; i < 6; i++){
            mouse.pt[i] = new Coordinates();
            Coordinates p = new Coordinates();
            p.x = getXCoordinates(xFactor, xStandard[i]);
            p.y = getYCoordinates(yFactor, yStandard[i]);
            mouse.pt[i] = p;
            xNew[i] = (int)mouse.pt[i].x;
            yNew[i] = (int)mouse.pt[i].y;
        }


        //Bot ausführen
        boolean timer = true;
        while (timer) {
            skin.mouseMove(xNew[0], yNew[0]);
            skin.delay(2000);
            skin.mouseMove(xNew[1], yNew[1]);
            skin.delay(2000);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(xNew[2], yNew[2]);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(xNew[3], yNew[3]);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(500);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(xNew[4], yNew[4]);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseMove(xNew[5], yNew[5]);
            skin.delay(250);
            skin.mousePress(InputEvent.BUTTON1_MASK);
            skin.delay(250);
            skin.mouseRelease(InputEvent.BUTTON1_MASK);

            //Bot wartet zufällige Anzahl an Sekunden bis zur erneuten Ausführung
            double dwaitTime = getRandom();
            long waitTime = (new Double(dwaitTime)).longValue();
            System.out.print(waitTime);
            Thread.sleep(waitTime);

        }
    }
}
 

Neue Themen


Oben