58
58
* queue. For example, {@code Robot.mouseMove} will actually move
59
59
* the mouse cursor instead of just generating mouse move events.
60
60
* <p>
61
+ * @apiNote When {@code autoWaitForIdle()} is enabled, mouse and key related methods
62
+ * cannot be called on the AWT EDT. This is because when {@code autoWaitForIdle()}
63
+ * is enabled, the mouse and key methods implicitly call {@code waitForIdle()}
64
+ * which will throw {@code IllegalThreadStateException} when called on the AWT EDT.
65
+ * In addition, screen capture operations can be lengthy
66
+ * and {@code delay(long ms)} clearly inserts a delay, so these also
67
+ * should not be called on the EDT. Taken together, this means that as much as possible,
68
+ * methods on this class should not be called on the EDT.
69
+ * <p>
61
70
* Note that some platforms require special privileges or extensions
62
71
* to access low-level input control. If the current platform configuration
63
72
* does not allow input control, an {@code AWTException} will be thrown
@@ -216,6 +225,8 @@ private static void checkIsScreenDevice(GraphicsDevice device) {
216
225
*
217
226
* @param x X position
218
227
* @param y Y position
228
+ * @throws IllegalThreadStateException if called on the AWT event dispatching
229
+ * thread and {@code isAutoWaitForIdle} would return true
219
230
*/
220
231
public synchronized void mouseMove (int x , int y ) {
221
232
peer .mouseMove (x , y );
@@ -268,6 +279,7 @@ public synchronized void mouseMove(int x, int y) {
268
279
* and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
269
280
* @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button
270
281
* that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
282
+ * @throws IllegalThreadStateException if called on the AWT event dispatching thread and {@code isAutoWaitForIdle} would return true
271
283
* @see #mouseRelease(int)
272
284
* @see InputEvent#getMaskForButton(int)
273
285
* @see Toolkit#areExtraMouseButtonsEnabled()
@@ -325,6 +337,7 @@ public synchronized void mousePress(int buttons) {
325
337
* and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
326
338
* @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button
327
339
* that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
340
+ * @throws IllegalThreadStateException if called on the AWT event dispatching thread and {@code isAutoWaitForIdle} would return true
328
341
* @see #mousePress(int)
329
342
* @see InputEvent#getMaskForButton(int)
330
343
* @see Toolkit#areExtraMouseButtonsEnabled()
@@ -349,6 +362,8 @@ private static void checkButtonsArgument(int buttons) {
349
362
* @param wheelAmt number of "notches" to move the mouse wheel
350
363
* Negative values indicate movement up/away from the user,
351
364
* positive values indicate movement down/towards the user.
365
+ * @throws IllegalThreadStateException if called on the AWT event dispatching
366
+ * thread and {@code isAutoWaitForIdle} would return true
352
367
*
353
368
* @since 1.4
354
369
*/
@@ -368,6 +383,8 @@ public synchronized void mouseWheel(int wheelAmt) {
368
383
* @param keycode Key to press (e.g. {@code KeyEvent.VK_A})
369
384
* @throws IllegalArgumentException if {@code keycode} is not
370
385
* a valid key
386
+ * @throws IllegalThreadStateException if called on the AWT event
387
+ * dispatching thread and {@code isAutoWaitForIdle} would return true
371
388
* @see #keyRelease(int)
372
389
* @see java.awt.event.KeyEvent
373
390
*/
@@ -387,7 +404,9 @@ public synchronized void keyPress(int keycode) {
387
404
* @param keycode Key to release (e.g. {@code KeyEvent.VK_A})
388
405
* @throws IllegalArgumentException if {@code keycode} is not a
389
406
* valid key
390
- * @see #keyPress(int)
407
+ * @throws IllegalThreadStateException if called on the AWT event
408
+ * dispatching thread and {@code isAutoWaitForIdle} would return true
409
+ * @see #keyPress(int)
391
410
* @see java.awt.event.KeyEvent
392
411
*/
393
412
public synchronized void keyRelease (int keycode ) {
@@ -487,6 +506,12 @@ public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
487
506
* nativeResImage = resolutionVariants.get(0);
488
507
* }
489
508
* }</pre>
509
+ *
510
+ * @apiNote It is recommended to avoid calling this method on
511
+ * the AWT Event Dispatch Thread since screen capture may be a lengthy
512
+ * operation, particularly if acquiring permissions is needed and involves
513
+ * user interaction.
514
+ *
490
515
* @param screenRect Rect to capture in screen coordinates
491
516
* @return The captured image
492
517
* @throws IllegalArgumentException if {@code screenRect} width and height
@@ -641,6 +666,10 @@ public synchronized boolean isAutoWaitForIdle() {
641
666
/**
642
667
* Sets whether this Robot automatically invokes {@code waitForIdle}
643
668
* after generating an event.
669
+ * <p>
670
+ * @apiNote Setting this to true means you cannot call mouse and key-controlling events
671
+ * on the AWT Event Dispatching Thread
672
+ *
644
673
* @param isOn Whether {@code waitForIdle} is automatically invoked
645
674
*/
646
675
public synchronized void setAutoWaitForIdle (boolean isOn ) {
@@ -692,6 +721,10 @@ private void autoDelay() {
692
721
* already set, this method returns immediately with the interrupt status
693
722
* set.
694
723
*
724
+ * @apiNote It is recommended to avoid calling this method on
725
+ * the AWT Event Dispatch Thread since delay may be a lengthy
726
+ * operation.
727
+ *
695
728
* @param ms time to sleep in milliseconds
696
729
* @throws IllegalArgumentException if {@code ms} is not between {@code 0}
697
730
* and {@code 60,000} milliseconds inclusive
0 commit comments