< prev index next >

src/java.desktop/share/classes/java/awt/Robot.java

Print this page




 360 
 361     /**
 362      * Releases a given key.
 363      * <p>
 364      * Key codes that have more than one physical key associated with them
 365      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 366      * left or right shift key) will map to the left key.
 367      *
 368      * @param   keycode Key to release (e.g. {@code KeyEvent.VK_A})
 369      * @throws  IllegalArgumentException if {@code keycode} is not a
 370      *          valid key
 371      * @see  #keyPress(int)
 372      * @see     java.awt.event.KeyEvent
 373      */
 374     public synchronized void keyRelease(int keycode) {
 375         checkKeycodeArgument(keycode);
 376         peer.keyRelease(keycode);
 377         afterEvent();
 378     }
 379 





















 380     private void checkKeycodeArgument(int keycode) {
 381         // rather than build a big table or switch statement here, we'll
 382         // just check that the key isn't VK_UNDEFINED and assume that the
 383         // peer implementations will throw an exception for other bogus
 384         // values e.g. -1, 999999
 385         if (keycode == KeyEvent.VK_UNDEFINED) {
 386             throw new IllegalArgumentException("Invalid key code");
 387         }
 388     }
 389 
 390     /**
 391      * Returns the color of a pixel at the given screen coordinates.
 392      * @param   x       X position of pixel
 393      * @param   y       Y position of pixel
 394      * @return  Color of the pixel
 395      */
 396     public synchronized Color getPixelColor(int x, int y) {
 397         AffineTransform tx = GraphicsEnvironment.
 398                 getLocalGraphicsEnvironment().getDefaultScreenDevice().
 399                 getDefaultConfiguration().getDefaultTransform();




 360 
 361     /**
 362      * Releases a given key.
 363      * <p>
 364      * Key codes that have more than one physical key associated with them
 365      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 366      * left or right shift key) will map to the left key.
 367      *
 368      * @param   keycode Key to release (e.g. {@code KeyEvent.VK_A})
 369      * @throws  IllegalArgumentException if {@code keycode} is not a
 370      *          valid key
 371      * @see  #keyPress(int)
 372      * @see     java.awt.event.KeyEvent
 373      */
 374     public synchronized void keyRelease(int keycode) {
 375         checkKeycodeArgument(keycode);
 376         peer.keyRelease(keycode);
 377         afterEvent();
 378     }
 379 
 380     /**
 381      * Presses and releases a given unicode key.  The key should be released
 382      * using the {@code keyPressUnicode} and {@code keyReleaseUnicode} method.
 383      * <p>
 384      *
 385      * @param   unicodeKey unicode key to press and release
 386      * @throws  IllegalArgumentException if {@code unicodeKey} is not
 387      *          a valid unicode key
 388      * @see     #keyPressUnicode(int)
 389      * @see     #keyReleaseUnicode(int)
 390      */
 391     public synchronized void keyUnicode(int unicodeKey) {
 392         checkKeycodeArgument(unicodeKey);
 393 
 394         peer.keyPressUnicode(unicodeKey);
 395         afterEvent();
 396 
 397         peer.keyReleaseUnicode(unicodeKey);
 398         afterEvent();
 399     }
 400 
 401     private void checkKeycodeArgument(int keycode) {
 402         // rather than build a big table or switch statement here, we'll
 403         // just check that the key isn't VK_UNDEFINED and assume that the
 404         // peer implementations will throw an exception for other bogus
 405         // values e.g. -1, 999999
 406         if (keycode == KeyEvent.VK_UNDEFINED) {
 407             throw new IllegalArgumentException("Invalid key code");
 408         }
 409     }
 410 
 411     /**
 412      * Returns the color of a pixel at the given screen coordinates.
 413      * @param   x       X position of pixel
 414      * @param   y       Y position of pixel
 415      * @return  Color of the pixel
 416      */
 417     public synchronized Color getPixelColor(int x, int y) {
 418         AffineTransform tx = GraphicsEnvironment.
 419                 getLocalGraphicsEnvironment().getDefaultScreenDevice().
 420                 getDefaultConfiguration().getDefaultTransform();


< prev index next >