Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pyautogui window handle

Using pyautogui is there a way to get a handle to a window so that I can ensure that a click is performed on that window only? In other words, if my window isn't in focus, then the click does not occur. Additionally, if my window isn't in focus then I bring it into focus and then perform the actions.

The way to identify a window could be an ID, window title etc similar to this https://autohotkey.com/docs/commands/WinGet.htm

Is there any other Python module that supports this kind of functionality?

like image 297
kronosjt Avatar asked May 04 '17 14:05

kronosjt


People also ask

How do I press the Windows key in Pyautogui?

To press these keys, call the press() function and pass it a string from the pyautogui. KEYBOARD_KEYS such as enter , esc , f1 .

Can Pyautogui be detected?

No, as far as I know, there is no way for a website to detect the device or software (such as PyAutoGUI) which is making inputs, however, a site could detect robotic mouse movement etc., and you will not be able to pass CAPTCHAs.

Is Pyautogui safe?

The python package PyAutoGUI was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as safe to use.


2 Answers

This code might help to get what window you want to minimize or maximize. Example: If you want to get a Chrome window titled "Stack Overflow",

    pyautogui.getWindowsWithTitle("Stack Overflow")[0].minimize()

Or if you want to minimize or maximize any file explorer window that titled "music", the same thing applies.

    pyautogui.getWindowsWithTitle("music")[0].maximize()

If you are not sure about which window you require, you can get a list using this

like image 89
Vasanth Prabakar Avatar answered Oct 24 '22 09:10

Vasanth Prabakar


Is there any other Python module that supports this kind of functionality?

https://github.com/pywinauto/pywinauto

https://pywinauto.readthedocs.io/en/latest/#some-similar-tools-for-comparison

enter image description here

like image 24
Claudio Avatar answered Oct 24 '22 11:10

Claudio