slashshot007
Active Member
- Joined
- May 6, 2006
- Sythe Gold
- 0
- Messages
- 164
Movemouse Smooth:
yeah.. credits go to flaming idiots for the code, i just converted it to java.
heres the import statements needed:
and heres the code
findColor
I made a basic findColor function - it probably could be done in less code, but i'm too lazy to try and fingure it out so this is what you're stuck with unless you know how to change it. It returns a Point if you can't figure that out from the code.
if it cannot find the color in the rectangle, it will return the point as x = -1, y = -1
x1 is the x coordinate of the upper left point of the Rectangle that will be searched. y1 is the y coordinate.
x2 is the x coordinate of the bottom right point of the Rectangle, and y2 is the Y coordinate.
heres the import statements needed:
and heres the code:
EDIT:I updated the findcolor code DRASTICALLY. Now is much more efficient. still does everything the same way though.
EDIT AGAIN:
ok i found a much more efficient method, i've been told that getPixelColor can get very slow so heres a much faster way:
usage remains the same
yeah.. credits go to flaming idiots for the code, i just converted it to java.
heres the import statements needed:
Code:
import java.awt.*;
and heres the code
Code:
public void SmoothMove(Point Destination, double Speed){
try {
Robot robot = new Robot();
PointerInfo PInfo = MouseInfo.getPointerInfo();
Point origin = PInfo.getLocation();
Point Difference = new Point((int)(Destination.getX() - PInfo.getLocation().getX()),(int)(Destination.getY() - PInfo.getLocation().getY()));
for(double Current = 0; Current < 1; Current+= (Speed/Math.sqrt(Math.pow(Difference.getX(),2) + Math.pow(Difference.getY(),2)))){
PInfo = MouseInfo.getPointerInfo();
robot.mouseMove((int)origin.getX() + (int)(Difference.getX() * Current),(int)origin.getY() + (int)(Difference.getY() * Current););
robot.setAutoDelay(3);
}
}catch(java.awt.AWTException exc) {
System.out.println("error");
}
}
findColor
I made a basic findColor function - it probably could be done in less code, but i'm too lazy to try and fingure it out so this is what you're stuck with unless you know how to change it. It returns a Point if you can't figure that out from the code.
if it cannot find the color in the rectangle, it will return the point as x = -1, y = -1
x1 is the x coordinate of the upper left point of the Rectangle that will be searched. y1 is the y coordinate.
x2 is the x coordinate of the bottom right point of the Rectangle, and y2 is the Y coordinate.
heres the import statements needed:
Code:
import java.awt.*;
and heres the code:
Code:
private static Point findColor(Color color, int x1, int y1, int x2, int y2){
try {
Robot robot = new Robot();
for(int x = x1; x<x2; x++)
for(int y = y1; y<y2;y++)
if(robot.getPixelColor(x,y).equals(color))
return new Point(x,y);
}catch(java.awt.AWTException exc) {
return new Point(-1,-1);
}
return new Point(-1,-1);
}
EDIT AGAIN:
ok i found a much more efficient method, i've been told that getPixelColor can get very slow so heres a much faster way:
usage remains the same
Code:
private static Point findColor(Color color, int x1, int y1, int x2, int y2){
try {
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(new Rectangle(x1-1,y1-1,Math.abs(x1-x2)+1,Math.abs(y1-y2)+1));
int colorint = color.getRGB();
for(int y = 0; y < y2-y1; y++)
for(int x = 0; x < x2-x1 ; x++)
if(image.getRGB(x,y)==colorint){
return new Point(x+x1,y+y1);
}catch(java.awt.AWTException exc) {
return new Point(-1,-1);
}
return new Point(-1,-1);
}












