コード例 #1
0
ファイル: mouse.c プロジェクト: mgregson/autopy
bool smoothlyMoveMouse(MMPoint endPoint)
{
	MMPoint pos = getMousePos();
	MMSize screenSize = getMainDisplaySize();
	double velo_x = 0.0, velo_y = 0.0;
	double distance;

	while ((distance = hypot(pos.x - endPoint.x, pos.y - endPoint.y)) > 1.0) {
		double gravity = DEADBEEF_UNIFORM(5.0, 500.0);
		double veloDistance;
		velo_x += (gravity * (ssize_t)(endPoint.x - pos.x)) / distance;
		velo_y += (gravity * (ssize_t)(endPoint.y - pos.y)) / distance;

		/* Normalize velocity to get a unit vector of length 1. */
		veloDistance = hypot(velo_x, velo_y);
		velo_x /= veloDistance;
		velo_y /= veloDistance;

		pos.x += lround(velo_x);
		pos.y += lround(velo_y);

		/* Make sure we are in the screen boundaries!
		 * (Strange things will happen if we are not.) */
		if (pos.x >= screenSize.width || pos.y >= screenSize.height) {
			return false;
		}

		moveMouse(pos);

		/* Wait 1 - 3 milliseconds. */
		usleep(DEADBEEF_RANDRANGE(1000, 3001));
	}

	return true;
}
コード例 #2
0
ファイル: autopy-bitmap-module.c プロジェクト: Riamse/autopy3
static PyObject *bitmap_capture_screen(PyObject *self, PyObject *arg)
{
	MMRect rect;
	MMBitmapRef bitmap = NULL;
	MMSize displaySize = getMainDisplaySize();

	if (arg == NULL || arg == Py_None) {
		rect = MMRectMake(0, 0, displaySize.width, displaySize.height);
	} else {
		if (!PyArg_ParseTuple(arg, "(kk)(kk)", &rect.origin.x,
		                                       &rect.origin.y,
		                                       &rect.size.width,
		                                       &rect.size.height)) {
			PyErr_SetString(PyExc_TypeError, "Argument is not a rect");
			return NULL;
		}

		if (rect.origin.x >= displaySize.width ||
		    rect.origin.y >= displaySize.height ||
		    rect.origin.x + rect.size.width > displaySize.width ||
		    rect.origin.y + rect.size.height > displaySize.height) {
			PyErr_SetString(PyExc_ValueError, "Rect out of bounds");
			return NULL;
		}
	}

	bitmap = copyMMBitmapFromDisplayInRect(rect);
	if (bitmap == NULL || bitmap->imageBuffer == NULL) {
		PyErr_SetString(PyExc_OSError,
		                "Could not copy RGB data from display");
		return NULL;
	}

	return BitmapObject_FromMMBitmap(bitmap);
}