捕捉鼠标的Xlib [英] capture mouse with Xlib

查看:233
本文介绍了捕捉鼠标的Xlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个简单的Xlib程序更改鼠标的行为(举一个例子,反转垂直运动)。我有捕获事件的一个问题。

I want to write a simple Xlib program changing the mouse behavior (to give an example, invert vertical movement). I have a problem with capturing the events.

我想code到


  • 在控制器捕获位置的变化(我谨鼠标向上, MotionEvent

  • 计算新的光标位置(一个new_x - = difference_x

  • 设置新的光标位置(移动指针下来, XWarpPointer ,prevent事件的发生在这里)

  • capture changes in the controllers position (I move mouse upward, MotionEvent)
  • calculate new cursor position (new_x -= difference_x)
  • set new cursor position ( move pointer down, XWarpPointer, prevent event generation here)

在code下面应该每次移动鼠标时捕获移动事件,但它产生只有当指针移动从一个窗口到另一个...如何捕获所有的运动事件的事件?

The code below should capture a motion event every time the mouse is moved, but it generates the event only when the pointer moves from one window to another... How to capture all the movement events?

#include "X11/Xlib.h"
#include "stdio.h"

int main(int argc, char *argv[])
{
    Display *display;
    Window root_window;
    XEvent event;

    display = XOpenDisplay(0);
    root_window = XRootWindow(display, 0);
    XSelectInput(display, root_window, PointerMotionMask );

    while(1) {
        XNextEvent( display, &event );
        switch( event.type ) {
            case MotionNotify:
                printf("x %d y %d\n", event.xmotion.x, event.xmotion.y );
                break;
        }
    }

    return 0;
}

相关阅读:

X11:如何我真的抢鼠标指针?

推荐答案

当你的程序接收鼠标事件,它接收到的事件的副本;副本也被发送到正在侦听这些事件(见的 XSelectInput(3) )。不使用 XGrabPointer不能覆盖这(3) 拿鼠标,将美元,收到的任何的鼠标活动部$ pvent其他程序独占所有权。总之,你不能真正做你正在尝试做的。

When your program receives mouse events, it receives a copy of the events; copies are also sent to other programs that are listening for those events (see XSelectInput(3)). You cannot override this without using XGrabPointer(3) to take exclusive ownership of the mouse, which will prevent other programs from receiving any mouse events. In short, you can't actually do what you are trying to do.

还要注意的是,如果客户端已指定 PointerMotion 在为它的一个窗口拒收传播面膜,您将不会收到其窗口内的任何指针移动事件(同样,除非你做一抢)。

Note also that if a client has specified PointerMotion in its do-not-propagate mask for one of its windows, you will not receive any pointer motion events within its window (again, unless you do a grab).

这篇关于捕捉鼠标的Xlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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