栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Linux,如何捕获屏幕并模拟鼠标移动

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux,如何捕获屏幕并模拟鼠标移动

//sg//Solution using Xlib for those who use Linux#include <X11/Xlib.h>#include<stdio.h>#include<unistd.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <X11/Xlib.h>#include <X11/Xutil.h>void mouseClick(int button){    Display *display = XOpenDisplay(NULL);    XEvent event;    if(display == NULL)    {        fprintf(stderr, "Cannot initialize the displayn");        exit(EXIT_FAILURE);    }    memset(&event, 0x00, sizeof(event));    event.type = ButtonPress;    event.xbutton.button = button;    event.xbutton.same_screen = True;    XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);    event.xbutton.subwindow = event.xbutton.window;    while(event.xbutton.subwindow)    {        event.xbutton.window = event.xbutton.subwindow;        XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);    }    if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errorn");    XFlush(display);    usleep(100000);    event.type = ButtonRelease;    event.xbutton.state = 0x100;    if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errorn");    XFlush(display);    XCloseDisplay(display);}int main(int argc,char * argv[]) {    int x , y;    x=atoi(argv[1]);    y=atoi(argv[2]);    Display *display = XOpenDisplay(0);    Window root = DefaultRootWindow(display);    XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);    mouseClick(Button1);    XFlush(display);    XCloseDisplay(display);    return 0;}

进行构建,然后模拟x的点击,y做:

$ ./a.out x y

$ g ++ -lX11 sgmousesim2.cpp

$ ./a.out 123 13

以防万一您仍然感兴趣。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/405953.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号