Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. add public static EnhancedRobot ROBOT; to the main class.
- 2. add this to the main class constructor
- EnhancedRobot robotH=null;
- try{
- robotH=new EnhancedRobot();
- }catch(Exception e){
- throw new NullPointerException("Robot failed to init!");
- }
- ROBOT=robotH;
- 3. add this class
- import java.awt.*;
- public class EnhancedRobot extends Robot{
- public EnhancedRobot()throws AWTException{super();}
- public void clickKeyKeyboard(int keyCode){
- try{
- keyPress(keyCode);
- keyRelease(keyCode);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- public void clickKeyMouse(int keyCode){
- try{
- mousePress(keyCode);
- mouseRelease(keyCode);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
- 4. to close the gui use
- MainClass.ROBOT.clickKeyKeyboard(KeyEvent.VK_ESCAPE);
Add Comment
Please, Sign In to add comment