PyQT Listen for SystemWide Key and mouse events

穿精又带淫゛_ 提交于 2019-12-22 01:06:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7812617/pyqt-listen-for-systemwide-key-and-mouse-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!