API java : Robot


java.awt
Class Robot

java.lang.Object
  extended by java.awt.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

Constructor Summary
Robot()
          Constructs a Robot object in the coordinate system of the primary screen.
Robot(GraphicsDevice screen)
          Creates a Robot for the given screen device.
 
Method Summary
 BufferedImage createScreenCapture(Rectangle screenRect)
          Creates an image containing pixels read from the screen.
 void delay(int ms)
          Sleeps for the specified time.
 int getAutoDelay()
          Returns the number of milliseconds this Robot sleeps after generating an event.
 Color getPixelColor(int x, int y)
          Returns the color of a pixel at the given screen coordinates.
 boolean isAutoWaitForIdle()
          Returns whether this Robot automatically invokes waitForIdle after generating an event.
 void keyPress(int keycode)
          Presses a given key.
 void keyRelease(int keycode)
          Releases a given key.
 void mouseMove(int x, int y)
          Moves mouse pointer to given screen coordinates.
 void mousePress(int buttons)
          Presses one or more mouse buttons.
 void mouseRelease(int buttons)
          Releases one or more mouse buttons.
 void mouseWheel(int wheelAmt)
          Rotates the scroll wheel on wheel-equipped mice.
 void setAutoDelay(int ms)
          Sets the number of milliseconds this Robot sleeps after generating an event.
 void setAutoWaitForIdle(boolean isOn)
          Sets whether this Robot automatically invokes waitForIdle after generating an event.
 String toString()
          Returns a string representation of this Robot.
 void waitForIdle()
          Waits until all events currently on the event queue have been processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Robot

public Robot()
      throws AWTException
Constructs a Robot object in the coordinate system of the primary screen.

Throws:
AWTException - if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
SecurityException - if createRobot permission is not granted
See Also:
GraphicsEnvironment.isHeadless(), SecurityManager.checkPermission(java.security.Permission), AWTPermission

Robot

public Robot(GraphicsDevice screen)
      throws AWTException
Creates a Robot for the given screen device. Coordinates passed to Robot method calls like mouseMove and createScreenCapture will be interpreted as being in the same coordinate system as the specified screen. Note that depending on the platform configuration, multiple screens may either:
  • share the same coordinate system to form a combined virtual screen
  • use different coordinate systems to act as independent screens
This constructor is meant for the latter case.

If screen devices are reconfigured such that the coordinate system is affected, the behavior of existing Robot objects is undefined.

Parameters:
screen - A screen GraphicsDevice indicating the coordinate system the Robot will operate in.
Throws:
AWTException - if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true.
IllegalArgumentException - if screen is not a screen GraphicsDevice.
SecurityException - if createRobot permission is not granted
See Also:
GraphicsEnvironment.isHeadless(), GraphicsDevice, SecurityManager.checkPermission(java.security.Permission), AWTPermission
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 method.

Parameters:
buttons - the Button mask; a combination of one or more of these flags:
  • InputEvent.BUTTON1_MASK
  • InputEvent.BUTTON2_MASK
  • InputEvent.BUTTON3_MASK
Throws:
IllegalArgumentException - if the button mask is not a valid combination
See Also:
mouseRelease(int)

mouseRelease

public void mouseRelease(int buttons)
Releases one or more mouse buttons.

Parameters:
buttons - the Button mask; a combination of one or more of these flags:
  • InputEvent.BUTTON1_MASK
  • InputEvent.BUTTON2_MASK
  • InputEvent.BUTTON3_MASK
Throws:
IllegalArgumentException - if the button mask is not a valid combination
See Also:
mousePress(int)

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

createScreenCapture

public BufferedImage createScreenCapture(Rectangle screenRect)
Creates an image containing pixels read from the screen. This image does not include the mouse cursor.

Parameters:
screenRect - Rect to capture in screen coordinates
Returns:
The captured image
Throws:
IllegalArgumentException - if screenRect width and height are not greater than zero
SecurityException - if readDisplayPixels permission is not granted
See Also:
SecurityManager.checkPermission(java.security.Permission), AWTPermission

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.

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Avertissement : Erreurs sur le site de l'infobrol

Sommaire du document

La base de données est temporairement indisponible

Le site rencontre momentanément quelques problèmes...

La base de données est temporairement indisponible (), ce qui explique que de nombreuses fonctions ne soient temporairement pas accessibles (par exemple les liens de navigation, les sommaires, etc.) et que l'affichage des pages soit beaucoup plus lent.

Veuillez réessayer dans quelques minutes (les tests automatiques sont effectués toutes les 15 minutes).

Je vous présente mes excuses pour le désagrément que cela engendre.

Steph.

 

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-1108
Document créé le 01/01/70 &am12Thu, 01 Jan 1970 00:00:00 +0000amvUTC; 00:00, dernière modification le Vendredi 17 Juin 2011, 10:12
Source du document imprimé : http://www.gaudry.be/ Document affiché 0 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (afficher)

La gestion des membres est momentanement desactivee pour des raisons de maintenance.

Navigation (masquer)
Apparence (afficher)
Stats (afficher)
867 documents
astuces.
niouzes.
definitions.
membres.
2290 messages.

Document genere en :
0,42 seconde
Citation (masquer)
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 09:55, toutes les heures sont au format GMTs