简体   繁体   English

在X11中钩住并阻止全局鼠标

[英]Hook and block globally mouse in X11

I need to hook globally mouse clicks and block last click if delay between two clicks is less than was set. 如果两次单击之间的延迟小于设置的时间,则需要全局挂接鼠标单击并阻止最后一次单击。

I wrote it for windows using WM_MOUSE_LL hook. 我使用WM_MOUSE_LL钩子为Windows编写了它。 I was unable to find any solution for me. 我找不到适合我的解决方案。 Is it even possible to globally block mouse click in X11 ? 甚至有可能在X11中全局阻止鼠标单击?

Windows full code Windows完整代码

As far as I know the standard X11 protocol doesn't allow this. 据我所知,标准的X11协议不允许这样做。 The XInput 2.0 extension might, but I doubt it.. while Windows assumes a single event queue that every program listens to, so that a program can intercept an event and prevent it from being sent down the queue to other listeners, every X11 client has its own independent queue and all clients that register interest in an event receive an independent copy of it in their queue. XInput 2.0扩展可能会,但我对此表示怀疑。.尽管Windows假定每个程序都侦听一个事件队列,以便程序可以拦截一个事件并防止事件沿着队列发送给其他侦听器,但每个X11客户端都有它自己的独立队列,并且所有注册对事件感兴趣的客户端都会在其队列中接收到它的独立副本。 This means that under normal circumstances it's impossible for an errant program to block other programs from running; 这意味着在正常情况下,错误的程序不可能阻止其他程序运行; but it also means that, for those times when a client must block other clients, it must do a server grab to prevent the server from processing events for any other client. 但是这也意味着,在某个客户端必须阻止其他客户端的情况下,它必须进行服务器抢夺,以防止该服务器处理任何其他客户端的事件。

Which means you can either 这意味着你可以

  • use an X server proxy (won't be hard, but will be pretty slower) 使用X服务器代理(不会很难,但会慢很多)

or 要么

  • do it on the input device level. 在输入设备级别执行此操作。 /dev/input/event<n> give you the input events. /dev/input/event<n>给您输入事件。 You can read off the keypresses there and decide if they should propagate further be consumed. 您可以在此处读取按键并决定是否应进一步传播这些按键。 Unfortunately there's no real documentation for this, but the header file linux/include/input.h is quite self explanatory. 不幸的是,没有真正的文档,但是头文件linux/include/input.h完全可以解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM