Robot is part of java.awt package . Robot class is basically used to generate native system input events for the purposes of self- running demos, test automation and other applications where control over mouse and keyboard is used.
Robot class generates events that can be used to control mouse, keyboard and can be used to take screenshots of the screen. In this article, we will implement Java Robot to move or drag the mouse to specified location.
Methods used :
- mouseMove(int x, int y) : move the mouse to a specified location of screen
- keyPress(int k) : presses a given key with a specified keycode
- keyRelease(int k) : releases a given key with a specified keycode
- mousePress(int b) : presses one or more mouse buttons.
- mouseRelease(int b) : Releases one or more mouse buttons.
Program 1 : Java program to move a mouse from the initial location to a specified location
Program 2 : Java program to drag a mouse from the one location to another location
Note: the code might not run in an online compiler please use an offline IDE.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Robot Class in Java AWT
- Java Robot Class | Get the pixel Color of a given point
- JSwing | Create a Magnifying tool using Java Robot
- Using predefined class name as Class or Variable name in Java
- Implement Pair Class with Unit Class in Java using JavaTuples
- Implement Triplet Class with Pair Class in Java using JavaTuples
- Implement Quintet Class with Quartet Class in Java using JavaTuples
- Implement Quartet Class with Triplet Class in Java using JavaTuples
- Implement Octet Class from Septet Class in Java using JavaTuples
- Implement Ennead Class from Octet Class in Java using JavaTuples
- Implement Sextet Class from Quintet Class in Java using JavaTuples
- Implement Septet Class from Sextet Class in Java using JavaTuples
- Implement Decade Class from Ennead Class in Java using JavaTuples
- Java.lang.Class class in Java | Set 1
- Java.lang.Class class in Java | Set 2
- Java.util.TimeZone Class (Set-2) | Example On TimeZone Class
- Difference between Abstract Class and Concrete Class in Java
- In Java, Can we call the main() method of a class from another class?
- Java Program to Check if a Given Class is a Local Inner Class
- Java Program to Check if a Given Class is an Anonymous Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.