I just started Java yesterday and been having some issues with conditional statements. Trying to disable and autoclicker when my mouse is up, and enable it when my mouse is down. But the clicker still clicks? How should I have this set up?
public class Random {
public boolean held;
Random(){
held = false;
}
public void printhi() {
System.out.print("hi");
}
public void setHeld(boolean held) throws AWTException {
this.held = held;
if(held == true) {
Robot robot = new Robot();
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.delay(100);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
if(held != true) {
}
}
}
CodePudding user response:
Just take another look at your logic:
if(held == true) {
if(held != true) {
}
}
I only removed some lines to hint you to the mistake :)
CodePudding user response:
public class Random {
public boolean held = false;
Random() {
}
public static void printhi() {
System.out.print("hi");
}
public void setHeld(boolean held) throws AWTException {
this.held = held;
if (held) {
Robot robot = new Robot();
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.delay(100);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
} else {
//do stuff
}
}
}