vendredi 31 juillet 2020

If Radio box is selected, switch between two clicking methods

So i have this code here, and it quite literally doesn't work and i just don't know why. It doesn't click, doesn't print out anything. My goal is to make the buttons function as switches between two methods of clicking. Right mouse button clicks, and Left mouse button clicks. Can anyone tell me why this doesn't function?

if (rbRightClickRadioButton.isSelected()) {
            System.out.println("RMB Clicker");

            Robot clicker = null;
            try {
                clicker = new Robot();
            } catch (AWTException e) {
                e.printStackTrace();
            }
            clicker.mousePress(InputEvent.BUTTON2_DOWN_MASK);
            clicker.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);

            Thread.sleep(delay);

            try {
                clicker = new Robot();
            } catch (AWTException e) {
                e.printStackTrace();
            }
            clicker.mousePress(InputEvent.BUTTON2_DOWN_MASK);
            clicker.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);

        } else if (rbRightClickRadioButton.isSelected()) {
            System.out.println("LMB Clicker");

            Robot clicker = null;
            try {
                clicker = new Robot();
            } catch (AWTException e) {
                e.printStackTrace();
            }
            clicker.mousePress(InputEvent.BUTTON2_DOWN_MASK);
            clicker.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);

            Thread.sleep(delay);

            try {
                clicker = new Robot();
            } catch (AWTException e) {
                e.printStackTrace();
            }
            clicker.mousePress(InputEvent.BUTTON2_DOWN_MASK);
            clicker.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);

Aucun commentaire:

Enregistrer un commentaire