linux界面鼠标捕捉,Linux,如何捕获屏幕,以及模拟鼠标移动

axiom..

15

//sg

//Solution using Xlib for those who use Linux

#include

#include

#include

#include

#include

#include

#include

#include

void mouseClick(int button)

{

Display *display = XOpenDisplay(NULL);

XEvent event;

if(display == NULL)

{

fprintf(stderr, "Cannot initialize the display\n");

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, "Error\n");

XFlush(display);

usleep(100000);

event.type = ButtonRelease;

event.xbutton.state = 0x100;

if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Error\n");

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处模拟点击,执行:

$ ./a.out x y

$ g ++ -lX11 sgmousesim2.cpp

$ ./a.out 123 13

以防你仍然感兴趣.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值