1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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 getScreenPixels(new Rectangle(x, y, 1, 1), c);
178 return c[0];
179 }
180
181 /**
182 * Creates an image containing pixels read from the screen.
183 * @param bounds the rect to capture in screen coordinates
184 * @return the array of pixels
185 */
186 @Override
187 public int [] getRGBPixels(final Rectangle bounds) {
188 int c[] = new int[bounds.width * bounds.height];
189 getScreenPixels(bounds, c);
190
191 return c;
192 }
193
194 private native void initRobot();
195 private native void mouseEvent(int displayID, int lastX, int lastY,
196 int buttonsState,
197 boolean isButtonsDownState,
198 boolean isMouseMove);
199 private native void keyEvent(int javaKeyCode, boolean keydown);
200 private void getScreenPixels(Rectangle r, int[] pixels){
201 nativeGetScreenPixels(r.x, r.y, r.width, r.height, pixels);
202 }
203 private native void nativeGetScreenPixels(int x, int y, int width, int height, int[] pixels);
204 }
|
1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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 }
|