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.
- Robot Class in Java AWT
- Java Robot Class | Get the pixel Color of a given point
- JSwing | Create a Magnifying tool using Java Robot
- Implement Ennead Class from Octet Class in Java using JavaTuples
- Implement Septet Class from Sextet Class in Java using JavaTuples
- Implement Sextet Class from Quintet 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 Triplet Class with Pair Class in Java using JavaTuples
- Implement Pair Class with Unit Class in Java using JavaTuples
- Implement Octet Class from Septet Class in Java using JavaTuples
- Implement Decade Class from Ennead Class in Java using JavaTuples
- Difference between Abstract Class and Concrete Class in Java
- Using predefined class name as Class or Variable name in Java
- Java.lang.Class class in Java | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.