3636@ SuppressWarnings ("WeakerAccess" )
3737public class Robot extends java .awt .Robot {
3838 private final static Logger LOGGER = LoggerFactory .getLogger (Robot .class );
39+ private final int DEFAULT_DELAY = 15 ;
3940 private final List <Integer > pressedKeys = new ArrayList <>();
4041
4142 public Robot (GraphicsDevice screen ) throws AWTException {
4243 super (screen );
43- // setAutoDelay(10 );
44+ setAutoDelay (DEFAULT_DELAY );
4445 //setAutoWaitForIdle(true);
4546 }
4647
@@ -61,6 +62,18 @@ public synchronized void keyRelease(int code) {
6162 pressedKeys .remove ((Integer ) code );
6263 }
6364
65+ @ Override
66+ public synchronized void mousePress (int buttons ) {
67+ super .mousePress (buttons );
68+ //waitForIdle();
69+ }
70+
71+ @ Override
72+ public synchronized void mouseRelease (int buttons ) {
73+ super .mouseRelease (buttons );
74+ //waitForIdle();
75+ }
76+
6477 public synchronized void pasteText (String text ) {
6578 final Clipboard clipboard = Toolkit .getDefaultToolkit ().getSystemClipboard ();
6679
@@ -75,7 +88,7 @@ public synchronized void pasteText(String text) {
7588 try {
7689 clipboard .setContents (new StringSelection (text ), null );
7790 waitForIdle ();
78- setAutoDelay (25 );
91+ setAutoDelay (50 );
7992
8093 if (SystemUtils .IS_OS_MAC_OSX )
8194 keyPress (KeyEvent .VK_META );
@@ -97,7 +110,7 @@ public synchronized void pasteText(String text) {
97110 } catch (Exception ex ) {
98111 LOGGER .warn ("Can't clear clipboard!" , ex );
99112 }
100- setAutoDelay (0 );
113+ setAutoDelay (DEFAULT_DELAY );
101114 }
102115 }
103116
@@ -117,9 +130,7 @@ public synchronized void printCharacter(char character) {
117130 String altCode = Integer .toString (character );
118131 for (int i = 0 ; i < altCode .length (); i ++) {
119132 char code = (char ) (altCode .charAt (i ) + '0' );
120- //delay(20);//may be needed for certain applications
121133 keyPress (code );
122- //delay(20);//uncomment if necessary
123134 keyRelease (code );
124135 }
125136 keyRelease (KeyEvent .VK_ALT );
0 commit comments