PyQt4 - detect global mouse click

给你一囗甜甜゛ 提交于 2019-12-25 07:59:31

问题


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.

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.

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

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?

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

Thanks!


回答1:


There are some cross-platform examples of how to do this with http://pypi.python.org/pypi/autopy/0.51




回答2:


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



来源:https://stackoverflow.com/questions/13150497/pyqt4-detect-global-mouse-click

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