5 Replies - 343 Views - Last Post: 21 June 2013 - 11:45 AM Rate Topic: -----

#1 UltimateGuitarHero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-January 13

?How Is this possible?

Posted 21 June 2013 - 09:50 AM

I am writing a program using the Robot.class and for some reason the and(&&) switched to or(||)
I am using EclipseSDK and this is the code that SOME HOW works:
while( mouseX != x || mouseY != y){}
/*
the rest of code just controls the mouses X and Y and that what the while loop is for, I wanted to give it the human touch where it looks like human making all of these actions.
this is the code that I intended to use but every thing was acting a or statement and where it just broke out of the
loop:


while(mouseX != x && mouseY != y){}


*/

This post has been edited by modi123_1: 21 June 2013 - 09:56 AM
Reason for edit:: fixed odd code tags


Is This A Good Question/Topic? 0
  • +

Replies To: ?How Is this possible?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9419
  • View blog
  • Posts: 35,398
  • Joined: 12-June 08

Re: ?How Is this possible?

Posted 21 June 2013 - 09:58 AM

what do you mean && is acting like || ?? As in the actions changed, or the actual characters in your code changed?
Was This Post Helpful? 0
  • +
  • -

#3 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1167
  • View blog
  • Posts: 7,216
  • Joined: 07-September 06

Re: ?How Is this possible?

Posted 21 June 2013 - 09:58 AM

The problem with using the AND is that when you get the x or the y coordinate to the proper place it will break out of the loop.

Now, the OR works because it looks and sees if the x is the proper coordinate, if it is that part is false, then it checks if the y coordinate is correct, if it isn't yet then that part is true, and a false OR true is true so the loop continues.

If you wanted, you could express the loop like so:
while(!(cursorX == x && cursorY == y))


So, that loops and sees if the x is correct, and the y is correct and then nots it. Given the same example as above there x is true and y is false we get: !(true && false) -> !(false) -> true so the loop would continue.

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#4 UltimateGuitarHero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-January 13

Re: ?How Is this possible?

Posted 21 June 2013 - 10:16 AM

ok, the (&&) is acting line the (||) and the (||) is acting like the (&&),but only in this loop.
so to sum up what i just said:
&& == ||
|| == ||
And i would just leave it alone seeing that i found what works but I want to know why this is happening.
I have never had this problem before.

Here is the actual code(prototype thats why its so sloppy):
package contorl;

import java.awt.Robot;

import java.awt.event.InputEvent;

import java.awt.event.KeyEvent;

public class Hack {
	
	private static int
		mouseX = 1,
		mouseY = 1,
		mouseSpeed = 1;
	
	
	Robot bot;
	
	char[] character;
	
	public Hack(){
		try{
			bot = new Robot();
			bot.setAutoDelay(6);
			//firefox();
			notepad();
			//convert("firefox",true);
		}catch(Exception e){
			e.printStackTrace();
			System.exit(0);
		}
	}
	
	public void notepad(){
		move(30,766);
		move(30,766);
		//move(150,755);
		//leftClick();
	}
	
	public void firefox(){
		move(30,766);
		move(30,750);
		//leftClick();
	}

	public void leftClick(){
		bot.mousePress(InputEvent.BUTTON1_MASK);
		bot.mouseRelease(InputEvent.BUTTON1_MASK);
	}
	
	public void rightClick(){
		bot.mousePress(InputEvent.BUTTON2_MASK);
		bot.mouseRelease(InputEvent.BUTTON2_MASK);
	}
	
	
	public void wheelClick(){
		bot.mousePress(InputEvent.BUTTON3_MASK);
		bot.mouseRelease(InputEvent.BUTTON3_MASK);
	}
	
	public void move(int x,int y){
		while( mouseX != x || mouseY != y){
			moveX(x);
			moveY(y);
			bot.mouseMove(mouseX,mouseY);
		}
		System.out.println("Done With mouse at X: " + mouseX);
		System.out.println("Done With mouse at Y: " + mouseY);

	}
	
	public void moveX(int x){
		if(mouseX < x){
			mouseX += mouseSpeed;
		}
		 if(mouseX > x){
			mouseX -= mouseSpeed;
		}
	}
	
	public void moveY(int y){
		if(mouseY < y){
			mouseY += mouseSpeed;
		}
		 if(mouseY > y){
			mouseY -= mouseSpeed;
		}
	}
	
	public void convert(String s,boolean B)/>{
		character = new char[s.length()];
		for(int i = 0;i < character.length;i++){
			character[i] = s.charAt(i);
			if(B)/>{
				String s2 = Character.toString(character[i]);
				System.out.println(s2);
				switch(character[i]){
				case 'a':
					bot.keyPress(KeyEvent.VK_A);
					bot.keyRelease(KeyEvent.VK_A);
				break;
				case 'b':
					bot.keyPress(KeyEvent.VK_B)/>;
					bot.keyRelease(KeyEvent.VK_B)/>;
				break;
				case 'c':
					bot.keyPress(KeyEvent.VK_C);
					bot.keyRelease(KeyEvent.VK_C);
				break;
				case 'd':
					bot.keyPress(KeyEvent.VK_D);
					bot.keyRelease(KeyEvent.VK_D);
				break;
				case 'e':
					bot.keyPress(KeyEvent.VK_E);
					bot.keyRelease(KeyEvent.VK_E);
				break;
				case 'f':
					bot.keyPress(KeyEvent.VK_F);
					bot.keyRelease(KeyEvent.VK_F);
				break;
				case 'g':
					bot.keyPress(KeyEvent.VK_G);
					bot.keyRelease(KeyEvent.VK_G);
				break;
				case 'h':
					bot.keyPress(KeyEvent.VK_H);
					bot.keyRelease(KeyEvent.VK_H);
				break;
				case 'i':
					bot.keyPress(KeyEvent.VK_I);
					bot.keyRelease(KeyEvent.VK_I);
				break;
				case 'j':
					bot.keyPress(KeyEvent.VK_J);
					bot.keyRelease(KeyEvent.VK_J);
				break;
				case 'k':
					bot.keyPress(KeyEvent.VK_K);
					bot.keyRelease(KeyEvent.VK_K);
				break;
				case 'l':
					bot.keyPress(KeyEvent.VK_L);
					bot.keyRelease(KeyEvent.VK_L);
				break;
				case 'm':
					bot.keyPress(KeyEvent.VK_M);
					bot.keyRelease(KeyEvent.VK_M);
				break;
				case 'n':
					bot.keyPress(KeyEvent.VK_N);
					bot.keyRelease(KeyEvent.VK_N);
				break;
				case 'o':
					bot.keyPress(KeyEvent.VK_O);
					bot.keyRelease(KeyEvent.VK_O);
				break;
				case 'p':
					bot.keyPress(KeyEvent.VK_P);
					bot.keyRelease(KeyEvent.VK_P);
				break;
				case 'q':
					bot.keyPress(KeyEvent.VK_Q);
					bot.keyRelease(KeyEvent.VK_Q);
				break;
				case 'r':
					bot.keyPress(KeyEvent.VK_R);
					bot.keyRelease(KeyEvent.VK_R);
				break;
				case 's':
					bot.keyPress(KeyEvent.VK_S);
					bot.keyRelease(KeyEvent.VK_S);
				break;
				case 't':
					bot.keyPress(KeyEvent.VK_T);
					bot.keyRelease(KeyEvent.VK_T);
				break;
				case 'u':
					bot.keyPress(KeyEvent.VK_U);
					bot.keyRelease(KeyEvent.VK_U);
				break;
				case 'v':
					bot.keyPress(KeyEvent.VK_V);
					bot.keyRelease(KeyEvent.VK_V);
				break;
				case 'w':
					bot.keyPress(KeyEvent.VK_W);
					bot.keyRelease(KeyEvent.VK_W);
				break;
				case 'x':
					bot.keyPress(KeyEvent.VK_X);
					bot.keyRelease(KeyEvent.VK_X);
				break;
				case 'y':
					bot.keyPress(KeyEvent.VK_Y);
					bot.keyRelease(KeyEvent.VK_Y);
				break;
				case 'z':
					bot.keyPress(KeyEvent.VK_Z);
					bot.keyRelease(KeyEvent.VK_Z);
				break;
				case ' ':
					bot.keyPress(KeyEvent.VK_SPACE);
					bot.keyRelease(KeyEvent.VK_SPACE);
				break;
				default:
				break;
				}
			}
		}
	}
	
	public static void main(String[] args){
		new Hack();
	}
}



yeah...HACK was the best name i could come up with. im thinking about trying it out on minecraft to auto build a house. NO BAD PLANS FOR THIS PROGRAM
Was This Post Helpful? 0
  • +
  • -

#5 UltimateGuitarHero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-January 13

Re: ?How Is this possible?

Posted 21 June 2013 - 10:24 AM

Alrite that worked thank you BetaWar and all that replied.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10693
  • View blog
  • Posts: 39,770
  • Joined: 27-December 08

Re: ?How Is this possible?

Posted 21 June 2013 - 11:45 AM

Why not just use the Minecraft API if you're going to be doing work with it? Why bother at all with Swing and Robot?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1