LapisSea

Untitled

Jan 10th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. 1. add public static EnhancedRobot ROBOT; to the main class.
  2.  
  3.  
  4. 2. add this to the main class constructor
  5. EnhancedRobot robotH=null;
  6. try{
  7. robotH=new EnhancedRobot();
  8. }catch(Exception e){
  9. throw new NullPointerException("Robot failed to init!");
  10. }
  11. ROBOT=robotH;
  12.  
  13.  
  14. 3. add this class
  15.  
  16. import java.awt.*;
  17.  
  18. public class EnhancedRobot extends Robot{
  19. public EnhancedRobot()throws AWTException{super();}
  20.  
  21. public void clickKeyKeyboard(int keyCode){
  22. try{
  23. keyPress(keyCode);
  24. keyRelease(keyCode);
  25. }catch(Exception e){
  26. e.printStackTrace();
  27. }
  28. }
  29. public void clickKeyMouse(int keyCode){
  30. try{
  31. mousePress(keyCode);
  32. mouseRelease(keyCode);
  33. }catch(Exception e){
  34. e.printStackTrace();
  35. }
  36. }
  37. }
  38.  
  39. 4. to close the gui use
  40. MainClass.ROBOT.clickKeyKeyboard(KeyEvent.VK_ESCAPE);
Add Comment
Please, Sign In to add comment