What function exactly does the Robot class in Java serve? Does it press keys or what?
Asked
Active
Viewed 511 times
-2
-
5-1, Read the API description for the class. From the API its says "The primary purpose of Robot is to facilitate automated testing of Java platform implementations.". It then explains how it does this. If there is something you don't understand then ask a specific question. That is make your question look like you have at least read the API before you post the question. – camickr Jul 10 '11 at 04:21
-
1How does one open a book, or search the internet? – Anti Earth Jul 19 '12 at 11:18
2 Answers
5
The robot class presses keys and uses the mouse.
Using this class, you can do five actions: press key, release key, move mouse, press mouse button, and release mouse button. It can also get the pixel color at a specific screen coordinate, or generate a screenshot in a BufferedImage
.
These methods do not just fake this within Java, they access low-level windowing system input events directly. By using these methods, you can program something that will interact with an application for testing or automation. The full API is here.

Erick Robertson
- 32,125
- 13
- 69
- 98