PyQT 监听系统范围的按键和鼠标事件
我正在尝试编写一个应用程序,用于侦听与某些模式匹配的系统范围内的按键和鼠标事件并响应它们。
我计划让应用程序在后台运行。不,它不是键盘记录器,它是一个具有良好意图的合法应用程序。
我计划使用 PyQT 或更可能使用 PySide 来实现此应用程序。当应用程序窗口聚焦时监听事件相当简单,但是当根本没有窗口时我该怎么做呢?
我专门在 OS X 上工作,但我更喜欢跨平台解决方案。
I'm trying to write an application that listens for systemwide key and mouse events matching certain patterns and responds to them.
I plan on making the application run in the background. No it is not a keylogger, it is a legit application with a good intent.
I'm planning to user PyQT or more likely PySide for this application. It's fairly simple to listen to events when an application window is focused, but how would I do it when there is no window at all?
I'm specifically working on OS X, but I would prefer a cross platform solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您几乎肯定需要一个第三方库来实现这一点。
我没有使用它的经验,但是 Qxt 扩展库有一个 QxtGlobalShortcut 类,并且有 PyQt 绑定pygs 的形状。这两个项目似乎都支持所有主要平台。
编辑
抱歉,我没有正确阅读您的问题。显然,您需要的不仅仅是全局快捷方式:(
做了更多研究后,它看起来像 QAbstractEventDispatcher.setEventFilter 可能很有希望,但是事实证明 Qt 只过滤发送到应用程序的事件 - 从不过滤系统范围的事件。需要库来解决这个问题。
I think you'll almost certainly need a third party library for this.
I have no experience of using it, but the Qxt extension library has a QxtGlobalShortcut class, and there are PyQt bindings for it the shape of pygs. Both projects seem to support all the major platforms.
EDIT
Sorry, I didn't read your question properly. You obviously need more than global shortcuts :(
After doing a little more research, it looked like QAbstractEventDispatcher.setEventFilter might have been promising. However, it turns out that Qt only filters events that are sent to the application - never system-wide events. So it definitely looks like a third-party library will be needed to solve this problem.