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; } }
/** * 在某坐标模拟鼠标消息 * * @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); }
/* * 在某坐标模拟鼠标消息 * * @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); }
void InputProvider::MoveMouse (int x, int y) { LOG_INPUT ("[%i shocker] InputProvider::MoveMouse (%i, %i)\n", getpid (), x, y); g_assert (xtest_available); g_assert (display); #if INTERMEDIATE_MOTION int current_x; int current_y; GetCursorPos (current_x, current_y); while (current_x != x || current_y != y) { XTestFakeMotionEvent (display, XSCREEN_OF_POINTER, current_x -= (current_x != x ? (current_x > x ? 1 : -1) : 0), current_y -= (current_y != y ? (current_y > y ? 1 : -1) : 0), CurrentTime); XFlush (display); } #else XTestFakeMotionEvent (display, XSCREEN_OF_POINTER, x, y, CurrentTime); XFlush (display); #endif }
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; }
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); }
void x11_shadow_input_extended_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; XTestGrabControl(subsystem->display, True); XTestFakeMotionEvent(subsystem->display, 0, x, y, CurrentTime); if (flags & PTR_XFLAGS_BUTTON1) button = 8; else if (flags & PTR_XFLAGS_BUTTON2) button = 9; if (flags & PTR_XFLAGS_DOWN) down = TRUE; if (button) XTestFakeButtonEvent(subsystem->display, button, down, CurrentTime); XTestGrabControl(subsystem->display, False); XFlush(subsystem->display); #endif }
/* 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 */
int main(int argc, char* argv[]) { signal(28, playpause); //killall -s 28 limitpointer will execute this function Display *dsp = XOpenDisplay( NULL ); if( !dsp ){ return 1; } int screen_width; if (argc == 2) screen_width = atoi(argv[1]); else screen_width = DisplayWidth(dsp, DefaultScreen(dsp)) / 2; Window focusWin = RootWindow(dsp, DefaultScreen(dsp)); XEvent event; while (true) { while (active) { XQueryPointer(dsp, focusWin, &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state); if (event.xbutton.x >= screen_width) XTestFakeMotionEvent(dsp, DefaultScreen(dsp), screen_width - 1, event.xbutton.y, 0); usleep(500); //0.5 ms } sleep (1); // 1 s } XCloseDisplay( dsp ); return 0; }
void CommandInterpreter::moveMouse(TACommand command) { int scale = 2; int absX = xOrigin + (command.xDifference / scale); int absY = yOrigin + (command.yDifference / scale); if ((absY < upBound) || (absY > downBound)) { printf("Out of bounds.\n"); cancel(lastEvent, command.type); XTestFakeMotionEvent(display, 0, xOrigin, yOrigin, CurrentTime); } XTestFakeMotionEvent(display, 0, absX, absY, CurrentTime); }
void xf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; int button = 0; BOOL down = FALSE; xfInfo* xfi = xfp->info; XTestGrabControl(xfi->display, True); XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime); if (flags & PTR_XFLAGS_BUTTON1) button = 8; else if (flags & PTR_XFLAGS_BUTTON2) button = 9; if (flags & PTR_XFLAGS_DOWN) down = TRUE; if (button != 0) XTestFakeButtonEvent(xfi->display, button, down, 0); XTestGrabControl(xfi->display, False); #endif }
void helper_mov_absxy(int x,int y) { XTestGrabControl(dpy,True); XTestFakeMotionEvent(dpy,-1,x,y,CurrentTime); XSync(dpy,False); XTestGrabControl(dpy,False); }
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 }
void move(int x, int y, bool relative=false){ // XTestFakeMotionEvent(display, -1, x, y, this->delay); if(relative){ XTestFakeRelativeMotionEvent(display, x, y, CurrentTime); }else{ XTestFakeMotionEvent(display, -1, x, y, CurrentTime); } XFlush(display); }
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; }
/** * 鼠标坐标移动 * * @x,@y 鼠标坐标 */ bool VirKey::MoveMouseTo(int x, int y) { assert(handle_); if (!XTestFakeMotionEvent(handle_, -1, x, y, CurrentTime)) { return false; } return true; }
/* * 鼠标坐标移动 * * @x,@y 鼠标坐标 */ bool sml_movemouseto(sml_handle handle, int x, int y) { assert(handle); if (!XTestFakeMotionEvent(handle, -1, x, y, CurrentTime)) { return false; } return true; }
void xf_input_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y) { xfPeerContext* xfp = (xfPeerContext*) input->context; xfInfo* xfi = xfp->info; pthread_mutex_lock(&(xfp->mutex)); #ifdef WITH_XTEST XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime); #endif pthread_mutex_unlock(&(xfp->mutex)); }
void InputProvider::MoveMouseDirect (int x, int y) { LOG_INPUT ("[%i shocker] InputProvider::MoveMouseDirect (%i, %i)\n", getpid (), x, y); g_assert (xtest_available); g_assert (display); XTestFakeMotionEvent (display, XSCREEN_OF_POINTER, x, y, CurrentTime); XFlush (display); }
/* * Event: Mouse Move * Input: double x [0.0, 1.0], double y [0.0, 1.0] * Input Error: return INPUT_ERROR; */ int Event::mouseMove(double x, double y){ if(x < 0 || x > 1 || y < 0 || y > 1){ return INPUT_ERROR;; } //in x11 display //the cursor mouse position is following the display resolution int point_x = x * QApplication::desktop()->width(); int point_y = y * QApplication::desktop()->height(); XTestFakeMotionEvent (display, -1, point_x, point_y, CurrentTime); XSync(display, 0); return 0; }
/* Moves the pointer to the given position */ void movePointer(int x, int y, int z) { /* Move pointer to center between touch points */ /* Experiments with XI events, not working yet */ // int axes[3] = {x, y, z}; // XDevice * dev = XOpenDevice(display, 17); // XTestFakeDeviceMotionEvent(display, dev, False, 0, axes, 2, 0); // XCloseDevice(display, dev); XTestFakeMotionEvent(display, -1, x, y, CurrentTime); XFlush(display); }
void SingleClickHoldEventManager::gestureInitialize(EventData ¶m) { if(!hasBeenInit){ initData(); hasBeenInit=true; } XTestFakeMotionEvent(dpy, 0, param.mousePosition.x, param.mousePosition.y, CurrentTime); XFlush(dpy); XTestFakeButtonEvent (dpy, button, true, CurrentTime); XFlush(dpy); }
void helper_init() { dpy=NULL; if(((int)(dpy=XOpenDisplay(NULL)))==NULL) printf("Error in opening display\n"); printf("Inside C\n"); XTestGrabControl(dpy,True); // XTestFakeButtonEvent(dpy,1,True,CurrentTime); XTestFakeMotionEvent(dpy,-1,0,0,CurrentTime); // XTestFakeButtonEvent(dpy,1,False,CurrentTime); XSync(dpy,False); XTestGrabControl(dpy,False); return; }
void CommandInterpreter::pan(TACommand command) { if (lastEvent != TACommandTypePan) cancel(lastEvent, command.type); switch (command.touch) { case TACommandTouchStart: lastEvent = TACommandTypePan; XTestFakeButtonEvent(display, 2, True, CurrentTime); XTestFakeMotionEvent(display, 0, xOrigin, yOrigin, CurrentTime); break; case TACommandTouchMove: moveMouse(command); break; case TACommandTouchEnd: XTestFakeButtonEvent(display, 2, False, CurrentTime); XTestFakeMotionEvent(display, 0, xOrigin, yOrigin, CurrentTime); lastEvent = NULL; break; default: break; } }
void xf_input_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; int button = 0; boolean down = false; xfInfo* xfi = xfp->info; pthread_mutex_lock(&(xfp->mutex)); XTestGrabControl(xfi->display, True); if (flags & PTR_FLAGS_WHEEL) { boolean negative = false; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) negative = true; button = (negative) ? 5 : 4; XTestFakeButtonEvent(xfi->display, button, True, 0); XTestFakeButtonEvent(xfi->display, button, False, 0); } else { if (flags & PTR_FLAGS_MOVE) XTestFakeMotionEvent(xfi->display, 0, x, y, 0); 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 != 0) XTestFakeButtonEvent(xfi->display, button, down, 0); } XTestGrabControl(xfi->display, False); pthread_mutex_unlock(&(xfp->mutex)); #endif }
void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; int button = 0; BOOL down = FALSE; xfInfo* xfi = xfp->info; XTestGrabControl(xfi->display, True); if (flags & PTR_FLAGS_WHEEL) { BOOL negative = FALSE; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) negative = TRUE; button = (negative) ? 5 : 4; XTestFakeButtonEvent(xfi->display, button, True, 0); XTestFakeButtonEvent(xfi->display, button, False, 0); } else { if (flags & PTR_FLAGS_MOVE) XTestFakeMotionEvent(xfi->display, 0, x, y, 0); 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 != 0) XTestFakeButtonEvent(xfi->display, button, down, 0); } XTestGrabControl(xfi->display, False); #endif }
int main (int argc, char *argv[]) { Display *display; int eventbase, errorbase, majorver, minorver; int x, y; struct timespec delay = { 0, 500000 }; if (argc != 3) { fprintf (stderr, "Usage: grabcontrol <x> <y>\n"); exit (1); } x = atoi (argv[1]); y = atoi (argv[2]); if ((display = XOpenDisplay(XDisplayName(NULL))) == NULL) { fprintf (stderr, "Can't connect to X display\n"); exit(1); } if (!XTestQueryExtension(display, &eventbase, &errorbase, &majorver, &minorver)) { fprintf (stderr, "Can't find XTest support\n"); exit(1); } XTestGrabControl(display, True); XTestFakeMotionEvent (display, DefaultScreen (display), x, y, CurrentTime); XTestFakeButtonEvent(display, 1, True, CurrentTime); nanosleep (&delay, NULL); XTestFakeButtonEvent(display, 1, False, CurrentTime); XTestGrabControl(display, False); XFlush (display); return 0; }
int main(int argc, char* argv[] ){ Display *dpy = XOpenDisplay (0); if (argc < 3){ usage(); exit(1); } int x=atoi(argv[1]); int y=atoi(argv[2]); if (!x || !y){ usage(); } //Only works with this loop, why? for (int i=0; i< 500; i++){ //XTestFakeRelativeMotionEvent(dpy,screenx,screeny,0.2); XTestFakeMotionEvent(dpy,DefaultScreen(dpy),x, y, 0); } return 0; }
int mouse_move1(int x, int y, Display *active_display) { int res = 0; Window win; int revert_to; static int is_xtest_available = -1; int ev, er, ma, mi; if (!active_display) { res = -1; return -1; } XGetInputFocus(active_display, &win, &revert_to); if (is_xtest_available == -1) is_xtest_available = XTestQueryExtension(active_display, &ev, &er, &ma, &mi); if (is_xtest_available) XTestFakeMotionEvent(active_display,DefaultScreen(active_display), x, y, CurrentTime); //flush events XFlush(active_display); if (res == BadValue || res == BadWindow) res = -1; return 1; }
void InputProvider::MoveMouseLogarithmic (int x, int y) { LOG_INPUT ("[%i shocker] InputProvider::MoveMouseLogarithmic (%i, %i)\n", getpid (), x, y); g_assert (xtest_available); g_assert (display); int current_x; int current_y; float mult; GetCursorPos (current_x, current_y); while (current_x != x || current_y != y) { if (current_x != x) { mult = abs (current_x - x) > 20 ? 3.0 : 2.0; if (abs (current_x - x) < 10) current_x += (current_x < x ? 1.0 : -1.0 ); else current_x += (current_x < x ? 1.0 : -1.0 ) * mult * log (1 + abs (current_x - x)); } if (current_y != y) { mult = abs (current_y - y) > 20 ? 3.0 : 2.0; if (abs (current_y - y) < 10) current_y += (current_y < y ? 1.0 : -1.0 ); else current_y += (current_y < y ? 1.0 : -1.0 ) * mult * log (1 + abs (current_y - y)); } XTestFakeMotionEvent (display, XSCREEN_OF_POINTER, current_x, current_y, CurrentTime); XFlush (display); usleep (MOVE_MOUSE_LOGARITHMIC_INTERVAL); } }