Beispiel #1
0
/**
 * 在某坐标模拟鼠标消息
 *
 * @x,@y 为鼠标坐标
 * @type 为鼠标按键类型
 * 	MLEFT 为左键,MMIDDLE 为中键,MRIGHT 为右键
 */
void VirKey::ClickAt(int x, int y, VirKeyMType type)
{
	assert(handle_);

	XEvent event;

	// 保存鼠标当前位置等信息
	XQueryPointer(  handle_, 
			RootWindow(handle_, DefaultScreen(handle_)), 
			&event.xbutton.root,
			&event.xbutton.window,
      			&event.xbutton.x_root,
			&event.xbutton.y_root,
      			&event.xbutton.x,
			&event.xbutton.y,
      			&event.xbutton.state);

	// 移动鼠标,-1 表示当前屏幕
	XTestFakeMotionEvent(handle_, -1, x, y, CurrentTime);

	// 模拟按下和松开鼠标
	XTestFakeButtonEvent(handle_, type, 1, CurrentTime);
	XTestFakeButtonEvent(handle_, type, 0, CurrentTime);

	// 移动鼠标到原先位置
	XTestFakeMotionEvent(handle_, -1, event.xbutton.x, event.xbutton.y, CurrentTime);
}
Beispiel #2
0
//actually creates an XWindows event  :)
void sendevent(const FakeEvent &e) {
    Display* display = QX11Info::display();

    switch (e.type) {
    case FakeEvent::MouseMove:
        if (e.move.x == 0 && e.move.y == 0) return;
        XTestFakeRelativeMotionEvent(display, e.move.x, e.move.y, 0);
        break;

    case FakeEvent::KeyUp:
        if (e.keycode == 0) return;
        XTestFakeKeyEvent(display, e.keycode, false, 0);
        break;

    case FakeEvent::KeyDown:
        if (e.keycode == 0) return;
        XTestFakeKeyEvent(display, e.keycode, true, 0);
        break;

    case FakeEvent::MouseUp:
        if (e.keycode == 0) return;
        XTestFakeButtonEvent(display, e.keycode, false, 0);
        break;

    case FakeEvent::MouseDown:
        if (e.keycode == 0) return;
        XTestFakeButtonEvent(display, e.keycode, true, 0);
        break;
    }
    XFlush(display);
}
Beispiel #3
0
int main(int argc, char **argv)
{
        Display *d;
        struct timespec interval;
        interval.tv_sec = 0;
        interval.tv_nsec = 100000000;

        if(!(d = XOpenDisplay(NULL))) {
                fprintf(stderr, "\"%s\" can't open.\n", XDisplayName(NULL));
                exit(EXIT_FAILURE);
        }

        int ignore;
        if(!(XQueryExtension(d, "XTEST", &ignore, &ignore, &ignore))) {
                fprintf(stderr, "\"XTEST\" extension disabled.\n");
                exit(EXIT_FAILURE);
        }

        while(1){
                XTestFakeButtonEvent(d, RMB, True, 0);
                XTestFakeButtonEvent(d, RMB, False, 0);
                nanosleep(&interval, NULL);
                XSync(d, False);
        }
        XCloseDisplay(d);
        exit(EXIT_SUCCESS);
}
Beispiel #4
0
void CommandInterpreter::zoom(TACommand command)
{
	int threshold = 20;
	
	if (lastEvent != TACommandTypeZoom)
		cancel(lastEvent, command.type);
    
	switch (command.touch)
	{
		case TACommandTouchStart:
			lastEvent = TACommandTypeZoom;
			XTestFakeButtonEvent(display, 3, True, CurrentTime);
            XTestFakeMotionEvent(display, 0, xOrigin, yOrigin, CurrentTime);
		break;
		case TACommandTouchMove:
		{
			if (command.zoomValue > 1.0)
				XTestFakeRelativeMotionEvent(display, 0, threshold, CurrentTime);
			if (command.zoomValue < 1.0)
				XTestFakeRelativeMotionEvent(display, 0, (-1 * threshold), CurrentTime);
		}
		break;
		case TACommandTouchEnd:
		{
			XTestFakeButtonEvent(display, 3, False, CurrentTime);
            XTestFakeMotionEvent(display, 0, xOrigin, yOrigin, CurrentTime);
			lastEvent = NULL;
		}
		break;
		default:
		break;
	}
}
void mouseClick(int button)
{
XTestFakeButtonEvent(dpy, button, True, CurrentTime);
XTestFakeButtonEvent(dpy, button, False, CurrentTime);
XFlush(dpy);

}
Beispiel #6
0
/* Simulate a click at (@x, @y). */
static void click(unsigned x, unsigned y)
{
	XTestFakeMotionEvent(Dpy, DefaultScreen(Dpy), x, y, 0);
	XTestFakeButtonEvent(Dpy, Button1, True, 0);
	XTestFakeButtonEvent(Dpy, Button1, False, 250);
	XFlush(Dpy);
} /* click */
Beispiel #7
0
void MouseClick::mouseClick() {
    for (int i = 0; i < this->times; i++) {
        XTestFakeButtonEvent(QX11Info::display(), this->button, true, 0);
        XTestFakeButtonEvent(QX11Info::display(), this->button, false, 0);
    }
    XFlush(QX11Info::display());
}
Beispiel #8
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
                           jclass cls,
                           jint wheelAmt) {
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
/* cleaner to give it its own command type, in case the implementation   */
/* needs to be changed later.  -bchristi, 6/20/01                        */

    int32_t repeat = abs(wheelAmt);
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
                                                 /* wheel down: button 5 */
    int32_t loopIdx;

    AWT_LOCK();

    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);

    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
                                                     /* wheelAmt == 0    */
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
    }
    XSync(awt_display, False);

    AWT_UNLOCK();
}
Beispiel #9
0
/*
 * 在某坐标模拟鼠标消息
 *
 * @x,@y 为鼠标坐标
 * @type 为鼠标按键类型
 * 	MLEFT 为左键,MMIDDLE 为中键,MRIGHT 为右键
 */
void sml_clickat(sml_handle handle, int x, int y, mktype_t type)
{
	assert(handle);

	XEvent event;

	// 保存鼠标当前位置等信息
	XQueryPointer(  handle, 
			RootWindow(handle, DefaultScreen(handle)), 
			&event.xbutton.root,
			&event.xbutton.window,
      			&event.xbutton.x_root,
			&event.xbutton.y_root,
      			&event.xbutton.x,
			&event.xbutton.y,
      			&event.xbutton.state);

	// 移动鼠标,-1 表示当前屏幕
	XTestFakeMotionEvent(handle, -1, x, y, CurrentTime);

	// 模拟按下和松开鼠标
	XTestFakeButtonEvent(handle, type, 1, CurrentTime);
	XTestFakeButtonEvent(handle, type, 0, CurrentTime);

	// 移动鼠标到原先位置
	XTestFakeMotionEvent(handle, -1, event.xbutton.x, event.xbutton.y, CurrentTime);
}
Beispiel #10
0
/* void MouseClick (in long button); */
NS_IMETHODIMP MainComponent::MouseClick(PRInt32 button)
{
    XTestFakeButtonEvent(display, button, True, CurrentTime);
    XTestFakeButtonEvent(display, button, False, CurrentTime);
    XSync(display,0);
    return NS_OK;
}
Beispiel #11
0
		void click(int button) {
		        Display *display = XOpenDisplay(NULL);
			XTestFakeButtonEvent (display, button, True,  CurrentTime);
			usleep(1);
                        XTestFakeButtonEvent (display, button, False, CurrentTime);
                        XFlush(display);
		        XCloseDisplay(display);
                }
Beispiel #12
0
void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y)
{
#ifdef WITH_XTEST
	int button = 0;
	BOOL down = FALSE;
	rdpShadowServer* server;
	rdpShadowSurface* surface;

	server = subsystem->server;
	surface = server->surface;

	x += surface->x;
	y += surface->y;

	if (server->shareSubRect)
	{
		x += server->subRect.left;
		y += server->subRect.top;
	}

	XTestGrabControl(subsystem->display, True);

	if (flags & PTR_FLAGS_WHEEL)
	{
		BOOL negative = FALSE;

		if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
			negative = TRUE;

		button = (negative) ? 5 : 4;

		XTestFakeButtonEvent(subsystem->display, button, True, CurrentTime);
		XTestFakeButtonEvent(subsystem->display, button, False, CurrentTime);
	}
	else
	{
		if (flags & PTR_FLAGS_MOVE)
			XTestFakeMotionEvent(subsystem->display, 0, x, y, CurrentTime);

		if (flags & PTR_FLAGS_BUTTON1)
			button = 1;
		else if (flags & PTR_FLAGS_BUTTON2)
			button = 3;
		else if (flags & PTR_FLAGS_BUTTON3)
			button = 2;

		if (flags & PTR_FLAGS_DOWN)
			down = TRUE;

		if (button)
			XTestFakeButtonEvent(subsystem->display, button, down, CurrentTime);
	}

	XTestGrabControl(subsystem->display, False);

	XFlush(subsystem->display);
#endif
}
int main(int argc, const char *argv[])
{
    struct cpn_opt opts[] = {
        CPN_OPTS_OPT_STRING('f', "--from-display", NULL, NULL, false),
        CPN_OPTS_OPT_STRING('t', "--to-display", NULL, NULL, false),
        CPN_OPTS_OPT_END
    };
    struct payload payload;
    struct cpn_thread t;
    Display *dpy;
    int i, retval = 0;

    if (cpn_opts_parse_cmd(opts, argc, argv) <  0)
        return -1;

    payload.dpy1 = opts[0].value.string;
    payload.dpy2 = opts[1].value.string;

    cpn_spawn(&t, process_events, &payload);

    if ((dpy = XOpenDisplay(payload.dpy1)) == NULL) {
        retval = -1;
        goto out;
    }

    if (!XTestFakeRelativeMotionEvent(dpy, 2000, 0, CurrentTime)) {
        retval = -1;
        goto out;
    }

    XFlush(dpy);
    usleep(10000);

    for (i = 0; i < REPEATS * 2; i++) {
        if (!XTestFakeButtonEvent(dpy, 1, True, CurrentTime)) {
            puts("Unable to generate fake button event");
            retval = -1;
            goto out;
        }
        XFlush(dpy);
        usleep(20);

        if (!XTestFakeButtonEvent(dpy, 1, False, CurrentTime)) {
            puts("Unable to generate fake button event");
            retval = -1;
            goto out;
        }
        XFlush(dpy);
        usleep(20);

        usleep(1000);
    }

out:
    cpn_join(&t, NULL);

    return retval;
}
int main() {
  Display *xdpy;
  Window root;
  char *display_name = NULL;
  int ver;
  
  if ( (display_name = getenv("DISPLAY")) == (void *)NULL) {
    fprintf(stderr, "Error: DISPLAY environment variable not set\n");
    exit(1);
  }

  printf("Display: %s\n", display_name);

  if ( (xdpy = XOpenDisplay(display_name)) == NULL) {
    fprintf(stderr, "Error: Can't open display: %s", display_name);
    exit(1);
  }

  if (XTestQueryExtension(xdpy, &ver, &ver, &ver, &ver) != True) {
    printf("No xtest :(\n");
    return 1;
  }

  {
    int control, alt, key_l, key_two, del;
    control = XKeysymToKeycode(xdpy, XStringToKeysym("Control_L"));
    alt = XKeysymToKeycode(xdpy, XStringToKeysym("Alt_L"));
    key_l = XKeysymToKeycode(xdpy, XStringToKeysym("L"));
    key_two = XKeysymToKeycode(xdpy, XStringToKeysym("2"));
    del = XKeysymToKeycode(xdpy, XStringToKeysym("BackSpace"));

    printf("%d %d %d %d\n", control, alt, key_l, key_two);

    return;
    XTestFakeKeyEvent(xdpy, alt, True, CurrentTime);
    XTestFakeKeyEvent(xdpy, key_two, True, CurrentTime);
    XTestFakeKeyEvent(xdpy, key_two, False, CurrentTime);
    XTestFakeKeyEvent(xdpy, alt, False, CurrentTime);

    XTestFakeKeyEvent(xdpy, control, True, 100);
    XTestFakeKeyEvent(xdpy, key_l, True, CurrentTime);
    XTestFakeKeyEvent(xdpy, key_l, False, CurrentTime);
    XTestFakeKeyEvent(xdpy, control, False, CurrentTime);

    XTestFakeMotionEvent(xdpy, 0, 50, 55, CurrentTime);
    //XTestFakeButtonEvent(xdpy, 1, True, CurrentTime);
    //XTestFakeButtonEvent(xdpy, 1, False, CurrentTime);
    XTestFakeKeyEvent(xdpy, del, True, 50);
    XTestFakeKeyEvent(xdpy, del, False, CurrentTime);
    XTestFakeButtonEvent(xdpy, 2, True, CurrentTime);
    XTestFakeButtonEvent(xdpy, 2, False, CurrentTime);
    XFlush(xdpy);
  }

  return 0;
}
Beispiel #15
0
/*
 * Event: Mouse Wheel
 * Input: int distance, default 5
 */
void Event::mouseRoll(int distance)
{
    //mouse roll, negative will roll reverse direction
    int timer = distance;
    while(timer > 0){
        XTestFakeButtonEvent (display, 5, True,  CurrentTime);
        timer --;
    }
    XTestFakeButtonEvent (display, 5, False,  CurrentTime);
}
Beispiel #16
0
/**
 * Function used to scroll the screen in the required direction.
 * This uses the magnitude to scroll the required amount in the direction. 
 * TODO Requires further fine tuning based on the requirements.
 */
void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection)	
{
	/* Direction should only be considered based on the scrollDirection. This
	 * Should not interfere. */
	int cleanScrollMagnitude = abs(scrollMagnitude);
	if (!(scrollDirection == DIRECTION_UP || scrollDirection == DIRECTION_DOWN))
	{
		return;
	}
	
	/* Set up the OS specific solution */
	#if defined(__APPLE__)
	
		CGWheelCount wheel = 1;
		CGEventRef event;
	
		/* Make scroll magnitude negative if we're scrolling down. */
		cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;
		
		event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
		CGEventPost(kCGHIDEventTap, event);
		
	#elif defined(USE_X11)

		int x;
		int dir = 4; /* Button 4 is up, 5 is down. */
		Display *display = XGetMainDisplay();
		
		if (scrollDirection == DIRECTION_DOWN)
		{
			dir = 5;
		}
	
		for (x = 0; x < cleanScrollMagnitude; x++)
		{
			XTestFakeButtonEvent(display, dir, 1, CurrentTime);
			XTestFakeButtonEvent(display, dir, 0, CurrentTime);
		}
		
		XFlush(display);
		
	#elif defined(IS_WINDOWS)
		//FIXME: Need to figure out why this code doesn't work on Windows XP.
		/*INPUT mouseScrollInput;
		mouseScrollInput.type = INPUT_MOUSE;
		mouseScrollInput.mi.dx = 0;
		mouseScrollInput.mi.dy = 0;
		mouseScrollInput.mi.dwFlags = MOUSEEVENTF_WHEEL;
		mouseScrollInput.mi.time = 0;
		mouseScrollInput.mi.dwExtraInfo = 0;
		mouseScrollInput.mi.mouseData = WHEEL_DELTA * scrollDirection * cleanScrollMagnitude;
		SendInput(1, &mouseScrollInput, sizeof(mouseScrollInput));*/
	#endif
}
Beispiel #17
0
void XMouseInterface::MouseWheelY(int offset)
{
    for(int i = abs(offset); i > 0; i--)
    {
        XTestFakeButtonEvent(m_display, offset>0?5:4,
                             True,
                             CurrentTime);
        XTestFakeButtonEvent(m_display, offset>0?5:4,
                             False,
                             CurrentTime);
    }
    XFlush(m_display);
}
Beispiel #18
0
bool XRSERVER::processButtonEvent(XRNETPTREVENT *event) {
	switch (event->type) {
	case XREVENT_PTR_DOWN:
		XTestFakeButtonEvent(this->display, event->button, True, CurrentTime);
		break;

	case XREVENT_PTR_UP:
		XTestFakeButtonEvent(this->display, event->button, False, CurrentTime);
		break;
	}
	this->flush();
	return true;
}
Beispiel #19
0
/*
 * 发送一个鼠标按键点击消息
 */
bool sml_mbuttonpressonce(sml_handle handle, mktype_t type)
{
	assert(handle);

	if (!XTestFakeButtonEvent(handle, type, 1, CurrentTime)) {
		return false;
	}

	if (!XTestFakeButtonEvent(handle, type, 0, CurrentTime)) {
		return false;
	}

	return true;
}
Beispiel #20
0
/*
 * Event: Mouse Release
 * Input: int left = 1, right = 2
 * Input Error: return INPUT_ERROR;
 */
int Event::mouseRelease(int left_or_right)
{
    if(left_or_right == 1){
        //left button up
        XTestFakeButtonEvent (display, 1, False,  CurrentTime);
        return 0;
    }else if(left_or_right == 2){
        //right button up
        XTestFakeButtonEvent (display, 3, False,  CurrentTime);
        return 0;
    }else {
        return INPUT_ERROR;
    }
}
Beispiel #21
0
/*
 * Event: Mouse Press
 * Input: int left = 1, right = 2
 * Input Error: return INPUT_ERROR
 */
int Event::mousePress(int left_or_right)
{
    if(left_or_right == 1){
        //left button down
        XTestFakeButtonEvent (display, 1, True,  CurrentTime);
        return 0;
    }else if(left_or_right == 2){
        //right button down
        XTestFakeButtonEvent (display, 3, True,  CurrentTime);
        return 0;
    }else {
        return INPUT_ERROR;
    }
}
Beispiel #22
0
void clickCode(screenControl sc, int code)
{
    if (code==1) XTestFakeButtonEvent(sc.disp, Button1, true, CurrentTime);
    if (code==2) XTestFakeButtonEvent(sc.disp, Button2, true, CurrentTime);
    if (code==3) XTestFakeButtonEvent(sc.disp, Button3, true, CurrentTime);
    if (code==4) XTestFakeButtonEvent(sc.disp, Button4, true, CurrentTime);
    if (code==5) XTestFakeButtonEvent(sc.disp, Button5, true, CurrentTime);
    if (code!=1) XTestFakeButtonEvent(sc.disp, Button1, false, CurrentTime);
    if (code!=2) XTestFakeButtonEvent(sc.disp, Button2, false, CurrentTime);
    if (code!=3) XTestFakeButtonEvent(sc.disp, Button3, false, CurrentTime);
    if (code!=4) XTestFakeButtonEvent(sc.disp, Button4, false, CurrentTime);
    if (code!=5) XTestFakeButtonEvent(sc.disp, Button5, false, CurrentTime);
    XSync(sc.disp, 0);
}
Beispiel #23
0
int main (int argc, char** argv)
{
    Display* dpy = XOpenDisplay(NULL);    
    int x0 = atoi(argv[1]), y0 = atoi(argv[2]), 
        x1 = atoi(argv[3]), y1 = atoi(argv[4]);
    
    XTestFakeMotionEvent(dpy, -1, x0, y0, CurrentTime);
    XTestFakeButtonEvent(dpy, 1, True, 7);
    XTestFakeMotionEvent(dpy, -1, x1, y1, 15);
    XTestFakeButtonEvent(dpy, 1, False, 7);
    XFlush(dpy);
    XCloseDisplay(dpy);
    return 0;
}
Beispiel #24
0
/**
 * 发送一个鼠标按键点击消息
 */
bool VirKey::MbuttonPressOnce(VirKeyMType type)
{
	assert(handle_);

	if (!XTestFakeButtonEvent(handle_, type, 1, CurrentTime)) {
		return false;
	}

	if (!XTestFakeButtonEvent(handle_, type, 0, CurrentTime)) {
		return false;
	}

	return true;
}
Beispiel #25
0
void
InputProvider::MouseRightClick (unsigned int delay)
{
	LOG_INPUT ("[%i shocker] InputProvider::MouseRightClick (%u)\n", getpid (), delay);
	g_assert (xtest_available);
	g_assert (display);

	XTestFakeButtonEvent (display, 3, true, CurrentTime);
	XFlush (display);
	sleep_ms (delay);

	XTestFakeButtonEvent (display, 3, false, CurrentTime);
	XFlush (display);
	sleep_ms (delay);
}
Beispiel #26
0
/*! Send press-wait-release sequence to X for mouse button no `arg'.
 * Parts of this sequence can be disabled by passing `False' for doPress or
 * doRelease.
 */
static void press(int arg, Bool doPress, Bool doRelease) {
	usleep(100000); /* wait for 0.1 s */
	if (doPress) {
		/* send press command */
		XTestFakeButtonEvent(dpy, arg, True, CurrentTime);
		XFlush(dpy);
		usleep(100000); /* wait for 0.1 s */
	}
	if (doRelease)
	{
		/* send release command */
		XTestFakeButtonEvent(dpy, arg, False, CurrentTime);
		XFlush(dpy);
	}
}
Beispiel #27
0
bool Mouse::send_mouse_button( int button_P, bool release_P )
    {
#ifdef HAVE_XTEST
    if( xtest())
        {
        // CHECKME tohle jeste potrebuje modifikatory
        // a asi i spravnou timestamp misto CurrentTime
        bool ret = XTestFakeButtonEvent( QX11Info::display(), button_P, True, CurrentTime );
        if( release_P )
            ret = ret && XTestFakeButtonEvent( QX11Info::display(), button_P, False, CurrentTime );
        return ret;
        }
#endif
    return false;
    }
Beispiel #28
0
static void
click(Window *w, Point p) {
	Rectangle r;
	Point rp;

	r = getwinrect(w);
	rp = subpt(r.max, p);

	XTestFakeMotionEvent(display, 0, rp.x, rp.y, 0);

	XTestFakeButtonEvent(display, 1, true, 0);
	XTestFakeButtonEvent(display, 1, false, 0);

	XTestFakeMotionEvent(display, 0, r.max.x, r.max.y, 0);
}
Beispiel #29
0
/*
 * Event: Mouse Click
 * Input: int left = 1, right = 2
 * Input Error: return INPUT_ERROR
 */
int Event::mouseClick(int left_or_right)
{
    if(left_or_right == 1){
        //left button click
        XTestFakeButtonEvent (display, 1, True,  CurrentTime);
        XTestFakeButtonEvent (display, 1, False,  CurrentTime);
        return 0;
    }else if(left_or_right == 2){
        //right button click
        XTestFakeButtonEvent (display, 3, True,  CurrentTime);
        XTestFakeButtonEvent (display, 3, False,  CurrentTime);
        return 0;
    }else {
        return INPUT_ERROR;
    }
}
Beispiel #30
0
void helper_release()
{
	XTestGrabControl(dpy,True);
	XTestFakeButtonEvent(dpy,1,False,CurrentTime);
	XSync(dpy,False);
	XTestGrabControl(dpy,False);
}