Pin It

Program to demonstrate how to create Mouse Event using the Robot class in Java

Program to demonstrate how to create Mouse Event using the Robot class in Java

package com.hubberspot.robot;

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

public class RobotMouseEvent {

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

            Robot robot = new Robot();
   
     robot.delay(2000);
   
     //moves the mouse to (x,y) position
     robot.mouseMove(100, 100);
   
     robot.delay(2000);
     robot.mouseMove(500, 500);
     //moves the mouse to (x,y) and left clicks mouse button
     robot.mousePress(InputEvent.BUTTON1_MASK);
     robot.mouseRelease(InputEvent.BUTTON1_MASK);
      
     robot.delay(2000);
     robot.mouseMove(300, 300);
     //moves the mouse to (x,y) and right clicks mouse button
     robot.mousePress(InputEvent.BUTTON3_MASK);
     robot.mouseRelease(InputEvent.BUTTON3_MASK);
       
     robot.delay(2000);
     robot.mouseMove(600, 600);
     robot.delay(2000);
     //moves the mouse to (x,y) and middle wheel clicks 
     robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
     robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
     // it scrolls the mouse wheel
     robot.mouseWheel(-100);
  
  
 } catch (AWTException e) {
   
    e.printStackTrace();
    }
  
    }

}



Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot