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?
Try using wxPython:
Just wanted to add in case it helps, I have a function for my program (It's a software for my PC's lighting I have this simple few line function:
On windows, you can use the python for windows extensions (http://sourceforge.net/projects/pywin32/):
Below code is for python 3:
(Found this on http://scott.sherrillmix.com/blog/programmer/active-window-logger/)
The following script should work on Linux, Windows and Mac. It is currently only tested on Linux (Ubuntu Mate Ubuntu 15.10).
Prerequisites
For Linux:
Install
wnck
(sudo apt-get install python-wnck
on Ubuntu, see libwnck.)For Windows:
Make sure
win32gui
is availableFor Mac:
Make sure
AppKit
is availableThe script
For Linux users: All the answers provided required additional modules like "wx" that had numerous errors installing ("pip" failed on build), but I was able to modify this solution quite easily -> original source. There were bugs in the original (Python TypeError on regex)
The advantage is it works without additional modules. If you want it to work across multiple platforms, it's just a matter of changing the command and regex strings to get the data you want based on the platform (with the standard if/else platform detection shown above sys.platform).
On a side note: import wnck only works with python2.x when installed with "sudo apt-get install python-wnck", since I was using python3.x the only option was pypie which I have not tested. Hope this helps someone else.