Java programs to control mouse events using awt.robot class
Hello everyone as i have told you in my last post i will give you the some programs to control the mouse events such as mouse right and left click , mouse scroll up and down event , mouse release event and other.
first program is to move mouse pointer on your screen :
import java.awt.Robot; public class MouseClass { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.mouseMove(300, 550); } }
now to generate left mouse click event right this code :
import java.awt.Robot; import java.awt.event.InputEvent; public class MouseClass { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); } }
now to generate right mouse click event right this code :
import java.awt.Robot; import java.awt.event.InputEvent; public class MouseClass { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); } }now to click and scroll the mouse write this code :import java.awt.Robot; import java.awt.event.InputEvent; public class MouseClass { public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.mousePress(InputEvent.BUTTON3_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK); robot.mouseWheel(-100); } }
Comments
Post a Comment