Java – Control the mouse pointer and click

Here is a small java programs that is use to control your mouse.

Move your mouse cursor position on screen.

package com.omt.mouse;

import java.awt.Robot;

public class Main {

	public static void main(String[] args) {
		try {

			Robot robot = new Robot();
			robot.mouseMove(300, 500);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Mouse left click

package com.omt.mouse;

import java.awt.Robot;
import java.awt.event.InputEvent;

public class Main {

	public static void main(String[] args) {
		try {

			Robot robot = new Robot();
			// Left Click
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Mouse middle click

package com.omt.mouse;

import java.awt.Robot;
import java.awt.event.InputEvent;

public class Main {

	public static void main(String[] args) {
		try {

			Robot robot = new Robot();
			// Middle Click
			robot.mousePress(InputEvent.BUTTON2_MASK);
			robot.mouseRelease(InputEvent.BUTTON2_MASK);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Mouse Right Click

package com.omt.mouse;

import java.awt.Robot;
import java.awt.event.InputEvent;

public class Main {

	public static void main(String[] args) {
		try {

			Robot robot = new Robot();
			// Right Click
			robot.mousePress(InputEvent.BUTTON3_MASK);
			robot.mouseRelease(InputEvent.BUTTON3_MASK);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Mouse Double Click

package com.omt.mouse;

import java.awt.Robot;
import java.awt.event.InputEvent;

public class Main {

	public static void main(String[] args) {
		try {

			Robot robot = new Robot();
			// Double click
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
Share