PyQt4 - detect global mouse click - python

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!

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

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

Related

PySimpleGUI in python: Disable window move by user(with CTRL+mouse1)

A window can be moved by holding down CTRL and Mouse1, I would love to deactivate it, or deactivate window moving in general.
My problem is, that I use the CTRL key to mark multiple images in my explorer.
After my image is marked, the image is processed in PIL, which takes like 100-200ms.
So when the user holds down CTRL and clicks mouse1, the image gets processed in PIL. The user releases mouse1 and moves to the next element, the whole window is moved a fair amount(~100 pixels], where the user is moving the mouse to.(I guess the mouse1 click is still in buffer, and gets not updated to "is_released", while the program is busy)
My code is way to split(multiple files) up and too long to post, but I think my question is pretty straightforward and simple enough. toggle/block/unblock move window ability. Favorably deactivating CTRL-move in general, so the user can still use the titlebar.
I searched the docs, and found window.move(), but putting the window back to the original position would not be a pretty solution...lol
Thank you.
Refer PySimpleGUI Call Reference
Option in Window
grab_anywhere_using_control
If True can use CONTROL key + left mouse mouse to click and drag to move the window. DEFAULT is TRUE. Unlike normal grab anywhere, it works on all elements.
window = sg.Window('Title', layout, grab_anywhere_using_control=False)

How to draw a square outside of the application window in python tkinter

Question: Is it possible to use python to draw a box anywhere on the screen, outside of the application window.
Background:
I have some mouse/keyboard macros I use for work, programmed in python pyautogui, and have to make new ones and adjust them frequently. I would like my program to be such that I can use my mouse to draw a box over any part of my screen over any application window, and record the coordinates of the box for use within my macros. The box would be used as the selector, and would disappear once recorded. Basically the same thing as when you hold down your left mouse button on your desktop to select multiple icons, except I would just need the coordinates of the box to be returned for use in the macros (which I can already do with pyautogui).
Is it possible to draw outside of the canvas window? Perhaps there is a way to hide the canvas window without hiding the contents within it?

Is it possible to move and click the mouse in an inactive window with Python?

Is there a way to make the mouse move to certain coordinates and click inside of a window that might be in the background or behind another window without losing focus.
The idea is to let it work in the background while I'm using the computer for something else.
I'm working with Python on Windows 10.

PySide2 pass mouse events to system

I'm using a QDialog with transparency enabled to select a region of the screen for a screen capture tool. When the user clicks inside the transparent widget I want to ignore the mouse event so that the system handles it. Is this possible?
I'm trying to achieve this on Linux.
Some things I have tried with no success:
QtWidgets.QWidget.setWindowFlags(QtCore.Qt.WindowTransparentForInput)
QtWidgets.QWidget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
QtWidgets.QWidget.setMask(QtGui.QRegion(self.geometry()))
Subclassing mousePressEvent and ignoring the event
You have to use the flag X11BypassWindowManagerHint so that you omit the window manager next to WindowTransparentForInput so that the system knows that it only has to show the window but does not notify you about the inputs.
w.setWindowFlags(w.windowFlags() |
QtCore.Qt.WindowTransparentForInput |
QtCore.Qt.X11BypassWindowManagerHint)

Python win32api mouse control losing focus

I'm using win32api in a Python script to control mouse movements. It's working fantastic, but as soon as I click (I also generate click events) outside my Python shell/IDE, all my mouse events immediately stop. If I click my shell/IDE again, control is restored.
It seems like mouse control is only working when my Python shell or IDE is the "active" window - is there any way to retain mouse control even after Python is sent to the background?
Turns out this was not a Python issue, but was an issue with the device I was using to generate mouse movements. A separate API call was required to allow this device to push events when its owner was out of focus.

Categories

Resources