48 */
49 public CRobot(Robot r, CGraphicsDevice d) {
50 fDevice = d;
51 initRobot();
52 }
53
54 @Override
55 public void dispose() {
56 }
57
58 /**
59 * Moves mouse pointer to given screen coordinates.
60 * @param x X position
61 * @param y Y position
62 */
63 @Override
64 public void mouseMove(int x, int y) {
65 mouseLastX = x;
66 mouseLastY = y;
67
68 mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
69 mouseButtonsState, true, true);
70 }
71
72 /**
73 * Presses one or more mouse buttons.
74 *
75 * @param buttons the button mask (combination of
76 * <code>InputEvent.BUTTON1/2/3_MASK</code>)
77 */
78 @Override
79 public void mousePress(int buttons) {
80 mouseButtonsState |= buttons;
81
82 mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
83 buttons, true, false);
84 }
85
86 /**
87 * Releases one or more mouse buttons.
88 *
89 * @param buttons the button mask (combination of
90 * <code>InputEvent.BUTTON1/2/3_MASK</code>)
91 */
92 @Override
93 public void mouseRelease(int buttons) {
94 mouseButtonsState &= ~buttons;
95
96 mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
97 buttons, false, false);
98 }
99
100 @Override
101 public native void mouseWheel(int wheelAmt);
102
103 /**
104 * Presses a given key.
105 * <p>
106 * Key codes that have more than one physical key associated with them
107 * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
108 * left or right shift key) will map to the left key.
109 * <p>
110 * Assumes that the
111 * peer implementations will throw an exception for other bogus
112 * values e.g. -1, 999999
113 *
114 * @param keycode the key to press (e.g. <code>KeyEvent.VK_A</code>)
115 */
116 @Override
146 public int getRGBPixel(int x, int y) {
147 int c[] = new int[1];
148 getScreenPixels(new Rectangle(x, y, 1, 1), c);
149 return c[0];
150 }
151
152 /**
153 * Creates an image containing pixels read from the screen.
154 * @param bounds the rect to capture in screen coordinates
155 * @return the array of pixels
156 */
157 @Override
158 public int [] getRGBPixels(final Rectangle bounds) {
159 int c[] = new int[bounds.width * bounds.height];
160 getScreenPixels(bounds, c);
161
162 return c;
163 }
164
165 private native void initRobot();
166 private native void mouseEvent(int screen, int lastX, int lastY,
167 int buttonsState,
168 boolean isButtonsDownState,
169 boolean isMouseMove);
170 private native void keyEvent(int javaKeyCode, boolean keydown);
171 private void getScreenPixels(Rectangle r, int[] pixels){
172 nativeGetScreenPixels(r.x, r.y, r.width, r.height, pixels);
173 }
174 private native void nativeGetScreenPixels(int x, int y, int width, int height, int[] pixels);
175 }
|
48 */
49 public CRobot(Robot r, CGraphicsDevice d) {
50 fDevice = d;
51 initRobot();
52 }
53
54 @Override
55 public void dispose() {
56 }
57
58 /**
59 * Moves mouse pointer to given screen coordinates.
60 * @param x X position
61 * @param y Y position
62 */
63 @Override
64 public void mouseMove(int x, int y) {
65 mouseLastX = x;
66 mouseLastY = y;
67
68 mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
69 mouseButtonsState, true, true);
70 }
71
72 /**
73 * Presses one or more mouse buttons.
74 *
75 * @param buttons the button mask (combination of
76 * <code>InputEvent.BUTTON1/2/3_MASK</code>)
77 */
78 @Override
79 public void mousePress(int buttons) {
80 mouseButtonsState |= buttons;
81
82 mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
83 buttons, true, false);
84 }
85
86 /**
87 * Releases one or more mouse buttons.
88 *
89 * @param buttons the button mask (combination of
90 * <code>InputEvent.BUTTON1/2/3_MASK</code>)
91 */
92 @Override
93 public void mouseRelease(int buttons) {
94 mouseButtonsState &= ~buttons;
95
96 mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
97 buttons, false, false);
98 }
99
100 @Override
101 public native void mouseWheel(int wheelAmt);
102
103 /**
104 * Presses a given key.
105 * <p>
106 * Key codes that have more than one physical key associated with them
107 * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the
108 * left or right shift key) will map to the left key.
109 * <p>
110 * Assumes that the
111 * peer implementations will throw an exception for other bogus
112 * values e.g. -1, 999999
113 *
114 * @param keycode the key to press (e.g. <code>KeyEvent.VK_A</code>)
115 */
116 @Override
146 public int getRGBPixel(int x, int y) {
147 int c[] = new int[1];
148 getScreenPixels(new Rectangle(x, y, 1, 1), c);
149 return c[0];
150 }
151
152 /**
153 * Creates an image containing pixels read from the screen.
154 * @param bounds the rect to capture in screen coordinates
155 * @return the array of pixels
156 */
157 @Override
158 public int [] getRGBPixels(final Rectangle bounds) {
159 int c[] = new int[bounds.width * bounds.height];
160 getScreenPixels(bounds, c);
161
162 return c;
163 }
164
165 private native void initRobot();
166 private native void mouseEvent(int displayID, int lastX, int lastY,
167 int buttonsState,
168 boolean isButtonsDownState,
169 boolean isMouseMove);
170 private native void keyEvent(int javaKeyCode, boolean keydown);
171 private void getScreenPixels(Rectangle r, int[] pixels){
172 nativeGetScreenPixels(r.x, r.y, r.width, r.height, pixels);
173 }
174 private native void nativeGetScreenPixels(int x, int y, int width, int height, int[] pixels);
175 }
|