Robot Class in Java

Robot class extends Object type. It's used to create system input events for self-running demos, test automation, as well as other uses where mouse and keyboard controls are essential. The primary reason for Robot class will be to offer automated testing of Java platform implementations.

For instance, the method Robot.mouseMove will move the cursor instead of merely creating a mouse move event.

However, many platforms need specific privileges to get into low-level input signal control. An AWTException will soon be thrown in the event the current platform settings don't allow input signal control when attempting to build the Robot examples. For instance, systems like X Window will throw the exception if TEST 2.2 natural extension isn't enabled(or not supported) by the X server.

If we're using Robot class for functions besides self-testing must manage these error states through the utilization of the exception handling mechanisms.

Java Robot things possess the capacity to take control from an individual, so we should be somewhat cautious.

The Robot class provides many instance methods where we can generate mouse and keyboard input signal, just as the input signals being given by a user. Some most employed case procedures accessible Robot class are:

Returns a BufferedImage benchmark value. This technique can be used to shoot the screen shot of the display inside the designated pixel values.

To transfer the mouse pointer into a given screen coordinates.

To Press the buttons of the mouse.

To release the buttons of the mouse.

keyPress ( int keycode )

To Press a given key of the computer keyboard.

keyRelease ( int keycode )

To release a given key of the computer keyboard.

To get the color of a pixel in the given screen coordinates. More info