< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java

Print this page




 149 
 150     /**
 151      * Releases a given key.
 152      * <p>
 153      * Key codes that have more than one physical key associated with them
 154      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 155      * left or right shift key) will map to the left key.
 156      * <p>
 157      * Assumes that the
 158      * peer implementations will throw an exception for other bogus
 159      * values e.g. -1, 999999
 160      *
 161      * @param keycode the key to release (e.g. {@code KeyEvent.VK_A})
 162      */
 163     @Override
 164     public void keyRelease(final int keycode) {
 165         keyEvent(keycode, false);
 166     }
 167 
 168     /**




































 169      * Returns the color of a pixel at the given screen coordinates.
 170      * @param x X position of pixel
 171      * @param y Y position of pixel
 172      * @return color of the pixel
 173      */
 174     @Override
 175     public int getRGBPixel(int x, int y) {
 176         int c[] = new int[1];
 177         double scale = fDevice.getScaleFactor();
 178         getScreenPixels(new Rectangle(x, y, (int) scale, (int) scale), c);
 179         return c[0];
 180     }
 181 
 182     /**
 183      * Creates an image containing pixels read from the screen.
 184      * @param bounds the rect to capture in screen coordinates
 185      * @return the array of pixels
 186      */
 187     @Override
 188     public int [] getRGBPixels(final Rectangle bounds) {
 189         int c[] = new int[bounds.width * bounds.height];
 190         getScreenPixels(bounds, c);
 191 
 192         return c;
 193     }
 194 
 195     private native void initRobot();
 196     private native void mouseEvent(int displayID, int lastX, int lastY,
 197                                    int buttonsState,
 198                                    boolean isButtonsDownState,
 199                                    boolean isMouseMove);
 200     private native void keyEvent(int javaKeyCode, boolean keydown);

 201     private void getScreenPixels(Rectangle r, int[] pixels){
 202         double scale = fDevice.getScaleFactor();
 203         nativeGetScreenPixels(r.x, r.y, r.width, r.height, scale, pixels);
 204     }
 205     private native void nativeGetScreenPixels(int x, int y, int width, int height, double scale, int[] pixels);
 206 }


 149 
 150     /**
 151      * Releases a given key.
 152      * <p>
 153      * Key codes that have more than one physical key associated with them
 154      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 155      * left or right shift key) will map to the left key.
 156      * <p>
 157      * Assumes that the
 158      * peer implementations will throw an exception for other bogus
 159      * values e.g. -1, 999999
 160      *
 161      * @param keycode the key to release (e.g. {@code KeyEvent.VK_A})
 162      */
 163     @Override
 164     public void keyRelease(final int keycode) {
 165         keyEvent(keycode, false);
 166     }
 167 
 168     /**
 169      * Presses a given key.
 170      * <p>
 171      * Key codes that have more than one physical key associated with them
 172      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 173      * left or right shift key) will map to the left key.
 174      * <p>
 175      * Assumes that the
 176      * peer implementations will throw an exception for other bogus
 177      * values e.g. -1, 999999
 178      *
 179      * @param keycode the key to press (e.g. {@code KeyEvent.VK_A})
 180      */
 181     @Override
 182     public void keyPressUnicode(final int key) {
 183         keyEventUnicode(key, true);
 184     }
 185 
 186     /**
 187      * Releases a given key.
 188      * <p>
 189      * Key codes that have more than one physical key associated with them
 190      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 191      * left or right shift key) will map to the left key.
 192      * <p>
 193      * Assumes that the
 194      * peer implementations will throw an exception for other bogus
 195      * values e.g. -1, 999999
 196      *
 197      * @param keycode the key to release (e.g. {@code KeyEvent.VK_A})
 198      */
 199     @Override
 200     public void keyReleaseUnicode(final int key) {
 201         keyEventUnicode(key, false);
 202     }
 203 
 204     /**
 205      * Returns the color of a pixel at the given screen coordinates.
 206      * @param x X position of pixel
 207      * @param y Y position of pixel
 208      * @return color of the pixel
 209      */
 210     @Override
 211     public int getRGBPixel(int x, int y) {
 212         int c[] = new int[1];
 213         double scale = fDevice.getScaleFactor();
 214         getScreenPixels(new Rectangle(x, y, (int) scale, (int) scale), c);
 215         return c[0];
 216     }
 217 
 218     /**
 219      * Creates an image containing pixels read from the screen.
 220      * @param bounds the rect to capture in screen coordinates
 221      * @return the array of pixels
 222      */
 223     @Override
 224     public int [] getRGBPixels(final Rectangle bounds) {
 225         int c[] = new int[bounds.width * bounds.height];
 226         getScreenPixels(bounds, c);
 227 
 228         return c;
 229     }
 230 
 231     private native void initRobot();
 232     private native void mouseEvent(int displayID, int lastX, int lastY,
 233                                    int buttonsState,
 234                                    boolean isButtonsDownState,
 235                                    boolean isMouseMove);
 236     private native void keyEvent(int javaKeyCode, boolean keydown);
 237     private native void keyEventUnicode(int javaKeyCode, boolean keydown);
 238     private void getScreenPixels(Rectangle r, int[] pixels){
 239         double scale = fDevice.getScaleFactor();
 240         nativeGetScreenPixels(r.x, r.y, r.width, r.height, scale, pixels);
 241     }
 242     private native void nativeGetScreenPixels(int x, int y, int width, int height, double scale, int[] pixels);
 243 }
< prev index next >