Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain Active window using Python

I would like to get the active window on the screen using python.

For example, the management interface of the router where you enter the username and password as admin

That admin interface is what I want to capture using python to automate the entry of username and password.

What imports would I require in order to do this?

like image 225
Vinod K Avatar asked Apr 22 '12 08:04

Vinod K


People also ask

How do I get the active window title in Python Mac?

activeApplication() . It will list details of the current active window including its title. This lists all windows of active application, not just the active window. E.g. in chrome open the developer tools on a separate window, you cannot distinguish which is active.

Can you control Windows with Python?

Make your OS work for you … a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls, but it has support for more complex actions like getting text data.

What is active window?

An active window is the currently focused window in the current window manager. Different window managers indicate the currently-active window in different ways and allow the user to switch between windows in different ways.


1 Answers

On windows, you can use the python for windows extensions (http://sourceforge.net/projects/pywin32/):

from win32gui import GetWindowText, GetForegroundWindow print GetWindowText(GetForegroundWindow()) 

Below code is for python 3:

from win32gui import GetWindowText, GetForegroundWindow print(GetWindowText(GetForegroundWindow())) 

(Found this on http://scott.sherrillmix.com/blog/programmer/active-window-logger/)

like image 135
William Saunders Avatar answered Sep 30 '22 23:09

William Saunders