PyQT侦听SystemWide按键和鼠标事件 [英] PyQT Listen for SystemWide Key and mouse events

查看:190
本文介绍了PyQT侦听SystemWide按键和鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个应用程序,以侦听与某些模式匹配的系统范围内的键和鼠标事件并对其进行响应.

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.

我打算为此应用程序使用PyQT或更可能使用PySide.当焦点对准应用程序窗口时,监听事件相当简单,但是当根本没有窗口时,我该怎么办呢?

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?

我专门在OS X上工作,但我希望使用跨平台解决方案.

I'm specifically working on OS X, but I would prefer a cross platform solution.

推荐答案

我认为您几乎肯定需要第三方库.

I think you'll almost certainly need a third party library for this.

我没有使用它的经验,但是 Qxt 扩展库具有一个 QxtGlobalShortcut 类,并且它具有 pygs .这两个项目似乎都支持所有主要平台.

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.

编辑

对不起,我没有正确阅读您的问题.您显然需要的不仅仅是全局快捷方式:(

Sorry, I didn't read your question properly. You obviously need more than global shortcuts :(

经过更多研究后,它看起来像 QAbstractEventDispatcher.setEventFilter 可能很有希望.但是,事实证明Qt仅过滤发送到应用程序的事件-绝不过滤系统范围的事件.因此,肯定看起来需要第三方库来解决此问题.

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.

这篇关于PyQT侦听SystemWide按键和鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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