Xlib XSendEvent单击事件在Ubuntu 12.04上的某些窗口内不起作用 [英] Xlib XSendEvent click event do not work inside of some windows on Ubuntu 12.04

查看:715
本文介绍了Xlib XSendEvent单击事件在Ubuntu 12.04上的某些窗口内不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ubuntu 12.04中使用xlib发送鼠标单击事件,当我在桌面栏图标中单击时,所有工作正常;当我在每个窗口的标题栏中单击时,所有工作正常(关闭,最小化,最大化)窗口),但在某些窗口中单击内部"不起作用,仅在我的qt创建者窗口中起作用,但是当我单击时,例如,主文件夹"图标然后将鼠标移到该文件夹​​中时,我无法在文件夹中进行任何单击或菜单栏,仅在窗口的标题栏中有效.

i'm trying to send mouse click event using xlib in a ubuntu 12.04, all works when i do the click in the desktop bar icons and works when i do click in the title bar of each window (close, minimize, maximize window) but in some windows doing a click inside do not work, only work in my qt creator window but when i click in, for example, Home folder icon then move the mouse inside the folder, i can't do any click in folders or menu bar, only works in the title bar of the windows.

也许是Ubuntu Unity桌面的错误?这是我在互联网上找到的代码:

Maybe is a bug of Ubuntu Unity desktop? here is my code that i find on internet:

#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, "Errore nell'apertura del 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, "Errore nell'invio dell'evento !!!\n");

    XFlush(display);

    usleep(100000);

    event.type = ButtonRelease;
    event.xbutton.state = 0x100;

    if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");

    XFlush(display);

    XCloseDisplay(display);
}

我的ubuntu在vmware播放器中,我使用Xlib的XWarpPointer移动光标,谢谢您的帮助.

My ubuntu is inside of a vmware player, i move the cursor using XWarpPointer of Xlib, thank you for any help.

推荐答案

我遇到了同样的问题,我只是使用Xext和Xtest扩展来解决了.

I had the same problem and I just solved it using Xext and Xtest extensions.

#include <X11/extensions/XTest.h>

int main(int argc, char ** argv)
{
    XEvent event;
    Display *dpy = XOpenDisplay (NULL);

    /* Fake the mouse button Press and Release events */
    XTestFakeButtonEvent (dpy, 1, True,  CurrentTime);
    XTestFakeButtonEvent (dpy, 1, False, CurrentTime);
    XCloseDisplay (dpy);
    return 0;
}

这篇关于Xlib XSendEvent单击事件在Ubuntu 12.04上的某些窗口内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆