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 checkMousePos(); 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 checkMousePos(); 96 mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY, 97 buttons, false, false); 98 } 99 100 /** 101 * Set unknown mouse location, if needed. 102 */ 103 private void checkMousePos() { 104 if (mouseLastX == MOUSE_LOCATION_UNKNOWN || 105 mouseLastY == MOUSE_LOCATION_UNKNOWN) { 106 107 Rectangle deviceBounds = fDevice.getDefaultConfiguration().getBounds(); 108 Point mousePos = CCursorManager.getInstance().getCursorPosition(); 109 110 if (mousePos.x < deviceBounds.x) { 116 117 if (mousePos.y < deviceBounds.y) { 118 mousePos.y = deviceBounds.y; 119 } 120 else if (mousePos.y > deviceBounds.y + deviceBounds.height) { 121 mousePos.y = deviceBounds.y + deviceBounds.height; 122 } 123 124 mouseLastX = mousePos.x; 125 mouseLastY = mousePos.y; 126 } 127 } 128 129 @Override 130 public native void mouseWheel(int wheelAmt); 131 132 /** 133 * Presses a given key. 134 * <p> 135 * Key codes that have more than one physical key associated with them 136 * (e.g. <code>KeyEvent.VK_SHIFT</code> could mean either the 137 * left or right shift key) will map to the left key. 138 * <p> 139 * Assumes that the 140 * peer implementations will throw an exception for other bogus 141 * values e.g. -1, 999999 142 * 143 * @param keycode the key to press (e.g. <code>KeyEvent.VK_A</code>) 144 */ 145 @Override 146 public void keyPress(final int keycode) { 147 keyEvent(keycode, true); 148 } 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</code> 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</code>) 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 /** | 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}) 77 */ 78 @Override 79 public void mousePress(int buttons) { 80 mouseButtonsState |= buttons; 81 checkMousePos(); 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}) 91 */ 92 @Override 93 public void mouseRelease(int buttons) { 94 mouseButtonsState &= ~buttons; 95 checkMousePos(); 96 mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY, 97 buttons, false, false); 98 } 99 100 /** 101 * Set unknown mouse location, if needed. 102 */ 103 private void checkMousePos() { 104 if (mouseLastX == MOUSE_LOCATION_UNKNOWN || 105 mouseLastY == MOUSE_LOCATION_UNKNOWN) { 106 107 Rectangle deviceBounds = fDevice.getDefaultConfiguration().getBounds(); 108 Point mousePos = CCursorManager.getInstance().getCursorPosition(); 109 110 if (mousePos.x < deviceBounds.x) { 116 117 if (mousePos.y < deviceBounds.y) { 118 mousePos.y = deviceBounds.y; 119 } 120 else if (mousePos.y > deviceBounds.y + deviceBounds.height) { 121 mousePos.y = deviceBounds.y + deviceBounds.height; 122 } 123 124 mouseLastX = mousePos.x; 125 mouseLastY = mousePos.y; 126 } 127 } 128 129 @Override 130 public native void mouseWheel(int wheelAmt); 131 132 /** 133 * Presses a given key. 134 * <p> 135 * Key codes that have more than one physical key associated with them 136 * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the 137 * left or right shift key) will map to the left key. 138 * <p> 139 * Assumes that the 140 * peer implementations will throw an exception for other bogus 141 * values e.g. -1, 999999 142 * 143 * @param keycode the key to press (e.g. {@code KeyEvent.VK_A}) 144 */ 145 @Override 146 public void keyPress(final int keycode) { 147 keyEvent(keycode, true); 148 } 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 getScreenPixels(new Rectangle(x, y, 1, 1), c); 178 return c[0]; 179 } 180 181 /** |