我试图点击浏览窗口。所以我假设我需要将XButtonEvents传递给我直接的窗口。它正在选择正确的窗口但是当在应该接收xevent的窗口上运行xev时它不会检测到任何内容。 更新: 所以xev仍然没有报告,但它抓住窗口我释放它。但是它不会点击按钮。
XButtonEvent createButtonEvent(Display *dp, Window win, bool press){
Window parent, rootwin, dischild;
rootwin = DefaultRootWindow(dp);
Window *child;
unsigned int numberChildern;
int px, py, i, rx, ry;
XWindowAttributes childAttr;
XButtonEvent buttonEvent;
buttonEvent.type=press?ButtonPress:ButtonRelease;
buttonEvent.send_event=false;
buttonEvent.display=dp;
buttonEvent.root=rootwin;
buttonEvent.subwindow=None;
buttonEvent.state=Button1Mask;
buttonEvent.same_screen=true;
XQueryTree(dp, rootwin, &rootwin, &parent, &child, &numberChildern);
px=0;
py=0;
if(!XQueryPointer(dp, rootwin, &buttonEvent.root, &dischild,
&px, &py, &rx, &ry, &buttonEvent.state))
{
fprintf(stderr, "Error cound not query pointer");
return buttonEvent;
}
for(i=0; i<numberChildern; i++)
{
if(child[i]==win)continue;
XGetWindowAttributes(dp, child[i], &childAttr);
if((px<childAttr.x)||(py<childAttr.y)||(px>(childAttr.x+childAttr.width))
||(py>(childAttr.y+childAttr.height)))continue;
else{
buttonEvent.x_root=rx;
buttonEvent.y_root=ry;
buttonEvent.x=px-childAttr.x;
buttonEvent.y=py-childAttr.y;
buttonEvent.window=child[i];
fprintf(stderr,"%d x=%d,y=%d,px=%d,py=%d\n",i,childAttr.x,childAttr.y,px,py);
return buttonEvent;
}
}
return buttonEvent;
}
然后我打电话发送如下:
buttonPress=createButtonEvent(dp, win, true);
buttonRelease=createButtonEvent(dp, win, false);
XSendEvent(dp, buttonPress.window, true, ButtonPressMask, (XEvent *)&buttonPress);
XSendEvent(dp, buttonRelease.window, true, ButtonReleaseMask, (XEvent *)&buttonRelease);