[source]Java Auto Color Clicker

Discussion in 'Programming General' started by slashshot007, Jan 17, 2008.

Thread Status:
Not open for further replies.
[source]Java Auto Color Clicker
  1. Unread #1 - Jan 17, 2008 at 6:51 AM
  2. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    [source]Java Auto Color Clicker

    yeah i felt like releasing my source, its not the most advanced looking code, but i tried to keep it looking nice.

    name this file Clicker.java
    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    
    public class Clicker{
    	
    	private static Timer tmrcoordinates;
    	private static Timer tmrClicker;
    	private static JLabel lblCoordinates;
    	private static JPanel colorpanel;
    	private static JTextField txtXCoord;
    	private static JTextField txtYCoord;
    	private static JTextField txtWindowX;
    	private static JTextField txtWindowY;
    	private static JTextField txtInterval;
    	private static Color colortoclick;
    	private static Point topleftCoord;
    	private static JButton btnSetColor;
    	private static JButton btnSetWindowCoords;
    	private static JButton btnstart;
    	private static JButton btnstop;
    	private static int Delay;
    	
    	public static void main(String[]args){
    		
    		ActionListener taskCoordinates = new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				PointerInfo PInfo = MouseInfo.getPointerInfo();
    				Point location = PInfo.getLocation();
    				lblCoordinates.setText((int)location.getX() + ", " + (int)location.getY());
    			  }
    		  };
    		ActionListener taskdone = new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				try {
    					  Robot robot = new Robot();
    					  colortoclick = robot.getPixelColor(Integer.parseInt(txtXCoord.getText()),Integer.parseInt(txtYCoord.getText()));
    					colorpanel.setBackground(colortoclick);
    				}catch(java.awt.AWTException exc) {
    				}
    			  }
    		  };
    		  ActionListener taskTmrClicker = new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				RSBot bot = new RSBot();
    				Point CenterPoint = new Point((int)topleftCoord.getX()+255,(int)topleftCoord.getY()+165);
    				Rectangle SearchRectangle = new Rectangle((int)topleftCoord.getX(),(int)topleftCoord.getY(),510,331);
    				Point ColorPoint = bot.FindColorSpiral(colortoclick,CenterPoint,SearchRectangle);
    				if(ColorPoint.equals(new Point(-1,-1))){
    					System.out.println("Unable to find color");
    				}else{
    					bot.SmoothMove(ColorPoint,5);
    					bot.waitms(100+(int)(Math.random()*200));
    					bot.ClickMouse("left");
    				}
    				tmrClicker.setDelay((Delay - 500) + (int)(Math.random()*1000));
    				txtInterval.setText(String.valueOf((Delay - 500) + (int)(Math.random()*1000)));
    			  }
    		  };
    		  ActionListener taskStartTmrClicker = new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				if(colortoclick == null || topleftCoord == null)
    					JOptionPane.showMessageDialog(null,"Please enter the color to click and/or the top left coordinate of the window first","Error",JOptionPane.ERROR_MESSAGE);
    				else{
    					Delay = Integer.parseInt(txtInterval.getText());
    					tmrClicker.setDelay(Delay);
    					tmrClicker.start();
    				}
    			  }
    		  };
    		  ActionListener taskStopTmrClicker = new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				tmrClicker.stop();
    			  }
    		  };
    		  ActionListener taskSetCoords = new ActionListener(){
    			public void actionPerformed(ActionEvent evt) {
    				topleftCoord = new Point(Integer.parseInt(txtWindowX.getText()),Integer.parseInt(txtWindowY.getText()));
    			  }
    		  };
    		
    		lblCoordinates = new JLabel("");
    		colorpanel = new JPanel();
    		colorpanel.setSize(20,20);
    		colorpanel.setBackground(Color.black);
    		txtXCoord = new JTextField("",2);
    		txtYCoord = new JTextField("",2);
    		txtWindowX = new JTextField("",2);
    		txtWindowY = new JTextField("",2);
    		colortoclick = new Color(0,0,0);
    		txtInterval = new JTextField("5000",4);
    		tmrcoordinates = new Timer(20,taskCoordinates);
    		tmrcoordinates.start();
    		tmrClicker = new Timer(5000,taskTmrClicker);
    		btnSetColor = new JButton("Set Color");
    		btnSetColor.addActionListener(taskdone);
    		btnSetWindowCoords = new JButton("Set Coordinates");
    		btnSetWindowCoords.addActionListener(taskSetCoords);
    		btnstart = new JButton("Start");
    		btnstart.addActionListener(taskStartTmrClicker);
    		btnstop = new JButton("Stop");
    		btnstop.addActionListener(taskStopTmrClicker);
    
    		ConstructGUI();
    	}
    
    	
    	private static void ConstructGUI(){
    		JLabel lblx = new JLabel("X:");
    		JLabel lbly = new JLabel("Y:");
    		JLabel lbl1 = new JLabel("Enter the X, and Y coordinates");
    		JLabel lbl2 = new JLabel("of the desired color");
    		JPanel Labels = new JPanel(new BorderLayout());
    		Labels.add(lbl1, BorderLayout.NORTH);
    		Labels.add(lbl2, BorderLayout.SOUTH);
    		
    		JPanel XCoordinate = new JPanel(new BorderLayout());
    		XCoordinate.add(lblx, BorderLayout.WEST);
    		XCoordinate.add(txtXCoord, BorderLayout.EAST);
    		JPanel YCoordinate = new JPanel(new BorderLayout());
    		YCoordinate.add(lbly, BorderLayout.WEST);
    		YCoordinate.add(txtYCoord, BorderLayout.EAST);
    		JPanel Coordinates = new JPanel(new BorderLayout());
    		Coordinates.add(XCoordinate, BorderLayout.WEST);
    		Coordinates.add(YCoordinate, BorderLayout.EAST);
    		
    		JPanel getColorWindow = new JPanel();
    		getColorWindow.setBorder(BorderFactory.createLineBorder(Color.black));
    		getColorWindow.setLayout(new BorderLayout());
    		getColorWindow.add(Labels,BorderLayout.NORTH);
    		getColorWindow.add(Coordinates,BorderLayout.WEST);
    		getColorWindow.add(btnSetColor, BorderLayout.EAST);
    		getColorWindow.add(colorpanel,BorderLayout.CENTER);
    			
    		JPanel getWindowCoords = new JPanel(new BorderLayout());
    		getWindowCoords.setBorder(BorderFactory.createLineBorder(Color.black));
    		  
    		JLabel lbl3 = new JLabel("Enter the Coordinates of the");
    		JLabel lbl4 = new JLabel("top-right corner of the RS2 screen.");
    		JPanel labelcoords = new JPanel(new BorderLayout());
    		labelcoords.add(lbl3,BorderLayout.NORTH);
    		labelcoords.add(lbl4,BorderLayout.SOUTH);
    		
    		JLabel lblWindowX = new JLabel("X:");
    		JLabel lblWindowY = new JLabel("Y:");
    		JPanel panelXWindow = new JPanel(new BorderLayout());
    		panelXWindow.add(lblWindowX,BorderLayout.WEST);
    		panelXWindow.add(txtWindowX,BorderLayout.EAST);
    		JPanel panelYWindow = new JPanel(new BorderLayout());
    		panelYWindow.add(lblWindowY,BorderLayout.WEST);
    		panelYWindow.add(txtWindowY,BorderLayout.EAST);
    
    		getWindowCoords.add(labelcoords, BorderLayout.NORTH);
    		getWindowCoords.add(panelXWindow,BorderLayout.WEST);
    		getWindowCoords.add(panelYWindow,BorderLayout.CENTER);
    		getWindowCoords.add(btnSetWindowCoords,BorderLayout.EAST);
    			  
    		JPanel panelButtons = new JPanel(new BorderLayout());
    		panelButtons.add(btnstart,BorderLayout.WEST);
    		panelButtons.add(btnstop,BorderLayout.EAST);
    		
    		JLabel lblinterval = new JLabel("Interval(Milliseconds):");
    		JPanel panelinterval = new JPanel(new BorderLayout());
    		panelinterval.add(lblinterval,BorderLayout.WEST);
    		panelinterval.add(txtInterval,BorderLayout.CENTER);
    		JPanel panelBottom = new JPanel(new BorderLayout());
    		panelBottom.setBorder(BorderFactory.createLineBorder(Color.black));
    		panelBottom.add(panelButtons,BorderLayout.WEST);
    		panelBottom.add(lblCoordinates,BorderLayout.EAST);
    		panelBottom.add(panelinterval,BorderLayout.NORTH);
    		
    		JFrame window = new JFrame("JClicker");
    		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		window.setLayout(new BorderLayout());
    		window.add(getColorWindow,BorderLayout.NORTH);
    		window.add(getWindowCoords,BorderLayout.CENTER);
    		window.add(panelBottom,BorderLayout.SOUTH);
    		window.pack();
    		window.setVisible(true);
    	}
    
    }
    you will also need to include this file in the same directory. Name it RSBot.java.
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    public class RSBot{
    	
    	public void ClickMouse(String button){
    		try{
    			Robot robot = new Robot();
    			if(button.toUpperCase().equals("LEFT")){
    				robot.mousePress(InputEvent.BUTTON1_MASK);
    				robot.setAutoDelay(200+(int)(Math.random()*200));
    				robot.mouseRelease(InputEvent.BUTTON1_MASK);
    			}else if(button.toUpperCase().equals("RIGHT")){
    				robot.mousePress(InputEvent.BUTTON3_MASK);
    				robot.setAutoDelay(200+(int)(Math.random()*200));
    				robot.mousePress(InputEvent.BUTTON3_MASK);
    			}
    		}catch(java.awt.AWTException exc) {
    			System.out.println("error");
    		}	
    	}
    	
    	public void waitms(int milliseconds){
    		try{
    			Integer milliseconds1 = new Integer(milliseconds);
    			Long ms = milliseconds1.longValue();
    			Thread.sleep(ms);
    		}catch(java.lang.InterruptedException exc){
    			System.out.println("error");
    		}
    	}
    	
    	public Point FindColorSpiral(Color color, Point StartPoint, Rectangle SearchArea){
    		//Credits to Cruel for this, SlashShot only converted it to Java
    		try{
    			Robot robot = new Robot();
    			BufferedImage image = robot.createScreenCapture(SearchArea);
    	   	 	int x = (int)StartPoint.getX() - (int)SearchArea.getX();
    				int y = (int)StartPoint.getY() - (int)SearchArea.getY();
    			int direction = 0, length = 1;
    			int rgbcolor = color.getRGB();
    			if (rgbcolor == image.getRGB(x, y))
    				return new Point((int)SearchArea.getX() + x, (int)SearchArea.getY() + y);
    			while ((x > 2) && (y > 2) && (x < SearchArea.getWidth() - 2) && (y < SearchArea.getHeight() - 2)){
    				for (int i = 1; i <= length; i++){
    					switch(direction){
    						case 0 :
    							y = y - 1;
    							break;
    						case 1 : 
    							x = x + 1;
    							break;
    						case 2 : 
    							y = y + 1;
    							break;
    						case 3 : 
    							x = x - 1;
    							break;
    					}
    					if (rgbcolor == image.getRGB(x, y))
    						return new Point((int)SearchArea.getX() + x, (int)SearchArea.getY() + y);
    				}	
    				direction = (direction + 1) % 4;
    				if ((direction % 2) == 0) 
    					length = length + 1;
    			}
    			return new Point(-1, -1);
    		}catch(java.awt.AWTException exc) {
    			return new Point(-1,-1);
    		}
    	}
    		
    	public Point findColor(Color color, Rectangle SearchArea){
    		try {
    			Robot robot = new Robot();
    			BufferedImage image = robot.createScreenCapture(SearchArea);
    			int colorint = color.getRGB();
    			for(int y = 0; y < (int)SearchArea.getHeight(); y++)
    				for(int x = 0; x < (int)SearchArea.getWidth(); x++)
    					if(image.getRGB(x,y)==colorint)				
    						return new Point(x+(int)SearchArea.getX(),y+(int)SearchArea.getY());
    		}catch(java.awt.AWTException exc) {
    			return new Point(-1,-1);
    		}
    		return new Point(-1,-1);
    	}
    	
    	public void SmoothMove(Point Destination, double Speed){
    		//Credits to Flaming Idiots for this as well, it was only converted to Java by SlashShot
       		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");
    		}
    	}
    }
    yep.
     
  3. Unread #2 - Nov 3, 2008 at 3:53 PM
  4. christb123
    Referrals:
    0

    christb123 Guest

    [source]Java Auto Color Clicker

    okay so i want to be able to use this on runescape but where do i paste all that text? please talk me through it
     
  5. Unread #3 - Nov 8, 2008 at 12:35 PM
  6. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    [source]Java Auto Color Clicker

    well its a java file, so you make it into two java files, with the names like i said above.
    Put them both into the same directory, and compile them, you can do this with the command line.
    just do in the command prompt
    Code:
    cd (insert the directory the files are in here)
    and then do
    Code:
    javac *.java
    to run it do
    Code:
    java Clicker
     
  7. Unread #4 - Jun 12, 2010 at 2:27 AM
  8. Deaths Mess
    Joined:
    Jun 12, 2010
    Posts:
    1
    Referrals:
    0
    Sythe Gold:
    0

    Deaths Mess Newcomer

    [source]Java Auto Color Clicker

    Hey

    I really want to understand how to do this, do i need to download another java program?
     
  9. Unread #5 - Jun 12, 2010 at 4:08 PM
  10. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    [source]Java Auto Color Clicker

    This thread is ancient.
     
< SharpF Bot Release!! | searching youtube subscriber pusher >

Users viewing this thread
1 guest
Thread Status:
Not open for further replies.


 
 
Adblock breaks this site