Results 1 to 7 of 7

Thread: Robot class

  1. #1
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default Robot class

    Hello people,

    I have made the following code.
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package javaapplication2;
    import java.awt.AWTException;
    import java.awt.Color;
    import java.awt.MouseInfo;
    import java.awt.Point;
    import java.awt.Robot;
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            try {
                Robot bot = new Robot();
                System.out.println("Please move your mouse to the monster to attack /n" +
                        "and keep it on it for 5 seconds."); // just some message   
    Point location = MouseInfo.getPointerInfo().getLocation(); //mouse position
    int mouseX = (int)location.getX();
    int mouseY = (int)location.getY();
    Color pixelcolor; //declaring the variable where the color of the pixel will be stored in
    bot.delay(5000); // 5 seconds sleep
    pixelcolor = bot.getPixelColor(mouseX, mouseY); //get the color of mouse position
    System.out.println(pixelcolor); // print it
    System.out.println("Bot will now start searching for monsters and attack.");
    
    
            }
            catch (AWTException AWT) {
                System.out.println("AWTException occured");
            }
        }
    }
    Now what i want to do is: search the screen for the color we have found earlier. I haven't found any method doing this. Does it exist?

    If not, i thought of the following. Move the mouse over the entire screen and check pixelcolor everytime, i know how to make this method i think. But would it be effective?
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    search the screen for the color we have found earlier
    Yes there are ways to do this. Look at the PixelGrabber class. There probably is sample code here if you Search for that class name.
    It would allow you to look at all the pixels for an image.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Use the Robot class to create a BufferedImage of the screen. Then you can search the BufferedImage one pixel at a time to find the matching pixels.

  4. #4
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    Pixelgrabber can only search pixels in a image, what i want to do is search pixels in a computer game.

    As for the bufferedImage how could i accomplish this?:confused:
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    search pixels in a computer game
    Where are these pixels?
    What does being in a game mean?

  6. #6
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    The pixels are on my screen, yet still i need to search a specifix color pixel on my screen.
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    Use the Robot class to capture the pixels on the screen to an image and then you can scan that image.

Similar Threads

  1. Help with Robot Class
    By protocos in forum Eclipse
    Replies: 11
    Last Post: 10-05-2009, 09:15 PM
  2. Help with Java Robot and Runtime Class
    By Rmond1254 in forum New To Java
    Replies: 1
    Last Post: 02-18-2009, 07:33 AM
  3. Newbie - Robot Class
    By drasgear in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 05:46 PM
  4. Robot Class
    By Jessie Madman in forum New To Java
    Replies: 3
    Last Post: 05-15-2008, 05:13 AM
  5. Robot Class
    By jfredrickson in forum New To Java
    Replies: 2
    Last Post: 07-11-2007, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •