PyQt4-检测全局鼠标单击 [英] PyQt4 - detect global mouse click

查看:214
本文介绍了PyQt4-检测全局鼠标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事的一个小项目的一部分涉及校准"要截取其屏幕的屏幕坐标.
通过屏幕",我指的是整个桌面,而不是我的GUI窗口.

A part of a small project I am working on involves 'calibrating' the coordinates of the screen of which to take a screen capture of.
By the 'screen', I refer to the entire desktop, not my GUI window.

当出现QDialog窗口(我已经将其子类化)时,将对坐标进行校准.
提示用户单击屏幕上的多个位置.
我需要该程序来记录在屏幕上任何地方发生的所有鼠标单击的位置-这些鼠标单击本身不在此窗口中,因为它们不在此窗口内.

The coordinates are calibrated when a QDialog window appears (which I've subclassed).
The user is prompted to click several locations on the screen.
I need the program to record the locations of all mouse clicks occuring anywhere on the screen - ones that don't natively trigger a QDialog mouseEvent, since they are outside this window.

显然,改写mouseEvent方法不起作用,因为QDialog无法接收到点击.

Obviously overwriting the mouseEvent method does not work, since the QDialog doesn't recieve the clicks.

如何捕获全局鼠标单击,以便在单击屏幕的任何部分时触发事件并将其发送到QDialog?

How can I capture global mouse clicks, so that an event is triggered and sent to the QDialog when any part of the screen is clicked?

(我更喜欢基于Qt的解决方案,但需要时可以向其他库开放).

(I'd prefer a Qt based solution, but am open to other libraries if need be).

谢谢!

推荐答案

我认为这是不可能的,而是使用pyHook, 让Qt抽出消息.

I've assumed this isn't possible and am instead using pyHook, letting Qt pump the messages.

这篇关于PyQt4-检测全局鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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