Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 20 of 20

Thread: Robot

  1. #1
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Robot

    First question was that I was trying to get the mouse to right click via java.awt.Robot.




    Also, how would I get Java to notice where it's positioned at? Like if it's in a certain place which has certain pixel colors.


    Now i'm stuck on this.
            		Color col = new Color(41, 47, 7);
            	        if(rob.getPixelColor(x, y) == col) {
            	            System.out.println("It worked..");
            	        }
            	        System.out.println(rob.getPixelColor(x, y));

    And the print out is:
    java.awt.Color[r=41,g=47,b=7]

    It keeps printing that out, whereas I want it to print out "It worked..". How else would I do this?
    Last edited by imsuperman05; December 26th, 2011 at 11:26 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Robot

    make the mouse right click
    That must be in the API doc. What methods look like they would do that?

    Same answer for the second question. Look at the methods in the API doc.

  3. #3
    Member Emperor_Xyn's Avatar
    Join Date
    Dec 2011
    Posts
    66
    My Mood
    Devilish
    Thanks
    21
    Thanked 2 Times in 2 Posts

    Default Re: Robot

    You move the mouse to location then you click...then release

  4. #4
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    What API doc? Robot.class?

  5. #5
    Member Emperor_Xyn's Avatar
    Join Date
    Dec 2011
    Posts
    66
    My Mood
    Devilish
    Thanks
    21
    Thanked 2 Times in 2 Posts

    Default Re: Robot

    Yes it's called robot, just call the Robot object and import Robot..

  6. #6
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by Emperor_Xyn View Post
    Yes it's called robot, just call the Robot object and import Robot..
    if ur not gonna help then dont post

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Robot

    Have you tried looking? The class is called Robot. Emperor_Xyn is trying to help. Please do some research yourself for how to use the Robot class. If you can't find something you're looking for in the docs, try searching the internet for it, then post any last questions you have on a forum and include any information you found while doing research.

  8. #8
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by helloworld922 View Post
    Have you tried looking? The class is called Robot. Emperor_Xyn is trying to help. Please do some research yourself for how to use the Robot class. If you can't find something you're looking for in the docs, try searching the internet for it, then post any last questions you have on a forum and include any information you found while doing research.
    I did look at it though, and I can't seem to find out how to right click.

  9. #9
    Member Emperor_Xyn's Avatar
    Join Date
    Dec 2011
    Posts
    66
    My Mood
    Devilish
    Thanks
    21
    Thanked 2 Times in 2 Posts

    Default Re: Robot

    Parameters:
    buttons - the Button mask; a combination of one or more of these flags:

    InputEvent.BUTTON1_MASK
    InputEvent.BUTTON2_MASK
    InputEvent.BUTTON3_MASK
    Right out of the API. 1 I believe is left click 2 middle button 3 is right click. I'm 80% sure although I haven't messed around with robot too much.

    Give it a try, 2 and 3 might be switched around i'm not sure. If it doesn't work report back and someone that does know can you help you.

    Also try http://www.javaprogrammingforums.com...bot-class.html


    Emperor_Xyn is trying to help.
    Thanks
    Last edited by Emperor_Xyn; December 26th, 2011 at 02:17 AM.

  10. #10
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by Emperor_Xyn View Post
    Right out of the API. 1 I believe is left click 2 middle button 3 is right click. I'm 80% sure although I haven't messed around with robot too much.

    Give it a try, 2 and 3 might be switched around i'm not sure. If it doesn't work report back and someone that does know can you help you.

    Also try http://www.javaprogrammingforums.com...bot-class.html



    Thanks
    Thank you ever so much, sir. This is exactly what I needed.

  11. #11
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Updated thread, down to one problem. Any help is appreciated now.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Robot

    If you'd mention the problem, maybe some one could help.
    Have you looked at the API doc for the Robot class? It doesn't have many methods you can use.
    Do any of them look like they will do what you want?

    You should NOT remove the original questions for the thread. It makes the first answers not make sense.

  13. #13
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by Norm View Post
    If you'd mention the problem, maybe some one could help.
    Have you looked at the API doc for the Robot class? It doesn't have many methods you can use.
    Do any of them look like they will do what you want?

    You should NOT remove the original questions for the thread. It makes the first answers not make sense.
    I'm very sorry sir. Yes, I'm looking over it now, and now i'm using BufferedImgae.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Robot

    Is that a question?

  15. #15
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by Norm View Post
    Is that a question?
    No, sorry. I'll rephrase it.
    Here's the source code.
    	public static void main(String...args) {
    	//while(true) {
            	try {
    			rob = new Robot();
            		rob.mouseMove(x, y);
            	        BufferedImage image = rob.createScreenCapture(new Rectangle(x, y, 335, 478));
            	        System.out.println(rob.getPixelColor(x, y));
            		rob.delay(800);
            	        rob.mousePress(InputEvent.BUTTON3_MASK);
            	        rob.mouseRelease(InputEvent.BUTTON3_MASK);
            	        rob.delay(800);
            	        y += 28;
            	        rob.mouseMove(x, y);
            	        System.out.println(inClient());
            	        rob.delay(800);
            	        rob.mousePress(InputEvent.BUTTON1_MASK);
            	        rob.mouseRelease(InputEvent.BUTTON1_MASK);
    		} catch (AWTException e) {
    		    e.printStackTrace();
    		}
    	  //}
    	}

    Now with the BufferedImage, what are the limits on this? What can I do with this? Is there any way I could find an image on the "Client" applet by the pixel colors or i guess by the BufferedImage?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Robot

    Now with the BufferedImage, what are the limits on this? What can I do with this?
    Sorry, that is a very general question. Can you be more specific?

    Is there any way I could find an image on the "Client" applet by the pixel colors
    If the applet has a GUI being displayed and that is captured as an image from the screen, you can look at the pixels in the captured image. The BufferedImage class has methods for looking at the pixels of the image so you should be able to "find" the image if you know what the colors of the pixels in the image are.

  17. #17
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by Norm View Post
    Sorry, that is a very general question. Can you be more specific?


    If the applet has a GUI being displayed and that is captured as an image from the screen, you can look at the pixels in the captured image. The BufferedImage class has methods for looking at the pixels of the image so you should be able to "find" the image if you know what the colors of the pixels in the image are.
    @First
    forgot it, i'll just read through it all.

    @Second
    static int x = 414;
    static int y = 315;

    image.getRGB(x, y);

    I keep getting an ArrayOutofBoundsException, I don't understand what coordinates it's asking for.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Robot

    What is the size of the image?
    Print out its height and width to see what its bounds are.

  19. #19
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Robot

    Quote Originally Posted by Norm View Post
    What is the size of the image?
    Print out its height and width to see what its bounds are.
    It's 335, 478.

    Thank you so much for you're time, I appreciate it. This will prob be the last thing I need.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Robot

    Ok, good luck.

Similar Threads

  1. Replies: 8
    Last Post: April 21st, 2013, 08:20 AM
  2. [SOLVED] Robot Exception
    By Kanyon in forum Exceptions
    Replies: 7
    Last Post: September 14th, 2011, 07:24 PM
  3. How to Sendkeys to an application in Java using the Robot Class
    By JavaPF in forum Java SE API Tutorials
    Replies: 6
    Last Post: August 4th, 2011, 12:13 AM
  4. Need Help for Robot class even on inactive window
    By jamsubzero in forum Java Theory & Questions
    Replies: 3
    Last Post: March 5th, 2011, 09:29 PM
  5. Robot help.
    By mlan in forum AWT / Java Swing
    Replies: 1
    Last Post: February 14th, 2010, 04:26 PM