PyQT Listen for SystemWide Key and mouse events

2019-04-17 00:05发布

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条回答
甜甜的少女心
2楼-- · 2019-04-17 00:47

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.

查看更多
登录 后发表回答