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 16 of 16

Thread: Almost woring bot!

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Almost woring bot!

    Hi!

    I was working on a bot for a game i use to play. All it has to do is check a screen pixel at (218, 60) and if its black press a few key.

    So i used the Robot class to make the keyPress and getScreenPixle. If the pixel is black then press 1 in a loop untill the pixel is a different color.

    Now this works when i run the program and have a notepad up, if the pixel is black i goet "11111111111...." in the notepad but soon as i swap to the game window press1() is executed once and then stops.

    However if i press enter ingame it opens the ingame chat and i get 111111 in the gamechat but soon as i get out of chat nothing is happening although skill with hotkey 1 be pressed in a loop.

    Here is the code:




    import java.awt.AWTException;
    import java.awt.Color;
    import java.awt.Robot;
    import java.awt.Window;
     
    public class KayListener {
    	static Robot r ;
     
    	public static void main(String[] args) throws AWTException{
     
     
     
    		r = new Robot();
    		Color c1;
    		Color c2;
    		c1 = r.getPixelColor(20, 20);
    		c2 = new Color(0,0,0);
     
    		while(true){
    			c1 = r.getPixelColor(218, 60);
     
    			if(c1.equals(c2)){
    				press1();
    			}
     
    		}
     
    	}
     
    	public static void press1(){
    		r.keyPress(49);
    	}
     
    }
    Last edited by iceman; September 12th, 2012 at 01:51 PM.


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

    Default Re: Almost woring bot!

    soon as i swap to the game window press1() is executed once and then stops.
    What are the values of c1 and c2 as the loop executes? If they are not equal then press1() won't be called.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    i have printed to see if the statement is true and it is true when it is supposed to be true, i also did a system.out.println("1 printed " + i)

    and the loop has beed executed 340 times in like 5 sek altho ingame i it olny got executed 1 time.

    loop.png

    Minor healing is at skill 1 so when pressing 1 should be used and it is being used but only once but loop is executed 300 times.

    loop.png
    Last edited by iceman; September 12th, 2012 at 03:58 PM.

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

    Default Re: Almost woring bot!

    Try adding a call to sleep() with different values inside the loop to see if there is a timing problem.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    How do i do that ?

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

    Default Re: Almost woring bot!

    Add a statement inside the loop that calls the Thread class's sleep() method.
    Experiment with different sleep times (say 50 to 500) and see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    Ok, ive tried it and it does the same thing but when pressing enter to get get to game chat it started to write "111111...." in chat but when i close chat to use the number for my skills id does not work.
    test.jpg

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

    Default Re: Almost woring bot!

    What keystrokes does the app you are trying to put input into require?
    What keys do you press when you enter data into the app manually?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    i got 10 skills and the hotkays for the skills are 1-9 and 0 , i wanna make a autohealer that checks a pixel and if it is black it means i have lost some health and i wanna spam key 1 respective 49 in ascii till the black pixle turns red.

    Problem is that ingame the kay 1 for healing is being pressed only once and then stops.

    BTW , thx for trying to help me ^^
    Last edited by iceman; September 12th, 2012 at 04:51 PM.

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

    Default Re: Almost woring bot!

    where is the input focus set to on the screen when the Robot presses the 1 key?
    Where is it typing the 1s???

    I know nothing about skills, autohealer, hotkeys etc
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    i run my java code and the swap to the gamewindow and it works but only once, it preforms the loop only once and then stops. I swap back to java but keep the program running and swap again to the gamewindow and again i use the heal but only once.

    So if i keep swaping windows it would work just as intended but that is not ideal.

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

    Default Re: Almost woring bot!

    it preforms the loop only once and then stops
    What do you mean by "stops"? Can you explain in detail? The program exits?
    How does the execution get out of the loop?
    Are there error messages?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    There are no errors and i don't want the loop to stop because i want to be able to see when my healt drops at any time the program is on and for now i exit the program manually via eclipse.

    When i say stop i mean that the loop is being executed and is true but ingame i don't not heal as if the Robot is not pressing 1 and that's what it is supposed to do.

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

    Default Re: Almost woring bot!

    Where on the screen is the output/focus where the 1s are being written?
    Try clicking somewhere that would show the 1s. Open Notepad and click on different places on its screen and you should see 1s being written where you click. That's what it does for me.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Almost woring bot!

    It does that for me too, but it does not use my healing skill ingame and the key to heal ingame is 1. So if i set focus to the game window and the program presses 1 all the time i should get healed but id does not happed.

    I think it has to do something with the window or maybe the keys being scripted. However thank you anyways ill try to ask my teacher for some guidance.

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

    Default Re: Almost woring bot!

    What happens when you click where you want the 1s to be written?
    If you don't understand my answer, don't ignore it, ask a question.

Tags for this Thread