Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.
java.awt

Class Robot


  • public class Robot
    extends Object
    This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.

    Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events.

    Note that some platforms require special privileges or extensions to access low-level input control. If the current platform configuration does not allow input control, an AWTException will be thrown when trying to construct Robot objects. For example, X-Window systems will throw the exception if the XTEST 2.2 standard extension is not supported (or not enabled) by the X server.

    Applications that use Robot for purposes other than self-testing should handle these error conditions gracefully.

    Since:
    1.3
    • Method Detail

      • mouseMove

        public void mouseMove(int x,
                     int y)
        Moves mouse pointer to given screen coordinates.
        Parameters:
        x - X position
        y - Y position
      • mousePress

        public void mousePress(int buttons)
        Presses one or more mouse buttons. The mouse buttons should be released using the mouseRelease(int) method.
        Parameters:
        buttons - the Button mask; a combination of one or more mouse button masks.

        It is allowed to use only a combination of valid values as a buttons parameter. A valid combination consists of InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK and values returned by the InputEvent.getMaskForButton(button) method. The valid combination also depends on a Toolkit.areExtraMouseButtonsEnabled() value as follows:

        • If support for extended mouse buttons is disabled by Java then it is allowed to use only the following standard button masks: InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK.
        • If support for extended mouse buttons is enabled by Java then it is allowed to use the standard button masks and masks for existing extended mouse buttons, if the mouse has more then three buttons. In that way, it is allowed to use the button masks corresponding to the buttons in the range from 1 to MouseInfo.getNumberOfButtons().
          It is recommended to use the InputEvent.getMaskForButton(button) method to obtain the mask for any mouse button by its number.

        The following standard button masks are also accepted:

        • InputEvent.BUTTON1_MASK
        • InputEvent.BUTTON2_MASK
        • InputEvent.BUTTON3_MASK
        However, it is recommended to use InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK instead. Either extended _DOWN_MASK or old _MASK values should be used, but both those models should not be mixed.
        Throws:
        IllegalArgumentException - if the buttons mask contains the mask for extra mouse button and support for extended mouse buttons is disabled by Java
        IllegalArgumentException - if the buttons mask contains the mask for extra mouse button that does not exist on the mouse and support for extended mouse buttons is enabled by Java
        See Also:
        mouseRelease(int), InputEvent.getMaskForButton(int), Toolkit.areExtraMouseButtonsEnabled(), MouseInfo.getNumberOfButtons(), MouseEvent
      • mouseRelease

        public void mouseRelease(int buttons)
        Releases one or more mouse buttons.
        Parameters:
        buttons - the Button mask; a combination of one or more mouse button masks.

        It is allowed to use only a combination of valid values as a buttons parameter. A valid combination consists of InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK and values returned by the InputEvent.getMaskForButton(button) method. The valid combination also depends on a Toolkit.areExtraMouseButtonsEnabled() value as follows:

        • If the support for extended mouse buttons is disabled by Java then it is allowed to use only the following standard button masks: InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK.
        • If the support for extended mouse buttons is enabled by Java then it is allowed to use the standard button masks and masks for existing extended mouse buttons, if the mouse has more then three buttons. In that way, it is allowed to use the button masks corresponding to the buttons in the range from 1 to MouseInfo.getNumberOfButtons().
          It is recommended to use the InputEvent.getMaskForButton(button) method to obtain the mask for any mouse button by its number.

        The following standard button masks are also accepted:

        • InputEvent.BUTTON1_MASK
        • InputEvent.BUTTON2_MASK
        • InputEvent.BUTTON3_MASK
        However, it is recommended to use InputEvent.BUTTON1_DOWN_MASK, InputEvent.BUTTON2_DOWN_MASK, InputEvent.BUTTON3_DOWN_MASK instead. Either extended _DOWN_MASK or old _MASK values should be used, but both those models should not be mixed.
        Throws:
        IllegalArgumentException - if the buttons mask contains the mask for extra mouse button and support for extended mouse buttons is disabled by Java
        IllegalArgumentException - if the buttons mask contains the mask for extra mouse button that does not exist on the mouse and support for extended mouse buttons is enabled by Java
        See Also:
        mousePress(int), InputEvent.getMaskForButton(int), Toolkit.areExtraMouseButtonsEnabled(), MouseInfo.getNumberOfButtons(), MouseEvent
      • mouseWheel

        public void mouseWheel(int wheelAmt)
        Rotates the scroll wheel on wheel-equipped mice.
        Parameters:
        wheelAmt - number of "notches" to move the mouse wheel Negative values indicate movement up/away from the user, positive values indicate movement down/towards the user.
        Since:
        1.4
      • keyPress

        public void keyPress(int keycode)
        Presses a given key. The key should be released using the keyRelease method.

        Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.

        Parameters:
        keycode - Key to press (e.g. KeyEvent.VK_A)
        Throws:
        IllegalArgumentException - if keycode is not a valid key
        See Also:
        keyRelease(int), KeyEvent
      • keyRelease

        public void keyRelease(int keycode)
        Releases a given key.

        Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.

        Parameters:
        keycode - Key to release (e.g. KeyEvent.VK_A)
        Throws:
        IllegalArgumentException - if keycode is not a valid key
        See Also:
        keyPress(int), KeyEvent
      • getPixelColor

        public Color getPixelColor(int x,
                          int y)
        Returns the color of a pixel at the given screen coordinates.
        Parameters:
        x - X position of pixel
        y - Y position of pixel
        Returns:
        Color of the pixel
      • isAutoWaitForIdle

        public boolean isAutoWaitForIdle()
        Returns whether this Robot automatically invokes waitForIdle after generating an event.
        Returns:
        Whether waitForIdle is automatically called
      • setAutoWaitForIdle

        public void setAutoWaitForIdle(boolean isOn)
        Sets whether this Robot automatically invokes waitForIdle after generating an event.
        Parameters:
        isOn - Whether waitForIdle is automatically invoked
      • getAutoDelay

        public int getAutoDelay()
        Returns the number of milliseconds this Robot sleeps after generating an event.
      • setAutoDelay

        public void setAutoDelay(int ms)
        Sets the number of milliseconds this Robot sleeps after generating an event.
        Throws:
        IllegalArgumentException - If ms is not between 0 and 60,000 milliseconds inclusive
      • delay

        public void delay(int ms)
        Sleeps for the specified time. To catch any InterruptedExceptions that occur, Thread.sleep() may be used instead.
        Parameters:
        ms - time to sleep in milliseconds
        Throws:
        IllegalArgumentException - if ms is not between 0 and 60,000 milliseconds inclusive
        See Also:
        Thread.sleep(long)
      • waitForIdle

        public void waitForIdle()
        Waits until all events currently on the event queue have been processed.
        Throws:
        IllegalThreadStateException - if called on the AWT event dispatching thread
      • toString

        public String toString()
        Returns a string representation of this Robot.
        Overrides:
        toString in class Object
        Returns:
        the string representation.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-java/awt/robot.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:fr Manuel PHP : https://docs.oracle.com

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut