Search code examples
pythonwindowspython-3.xkeypressminimize

Detecting keypresses in Windows to automate window functions in python


I'm creating an application to automatically perform keystrokes into the same, multiple windows that are open at the same time. These windows are all child windows from a parent.

For example, there are four windows and I want to press a key that will send CTRL-K to them, then immediately send WIN+M to all of them. After some time, I want to press another key that will then send SHIFT+WIN+M, and then CTRL+O.

I'm stuck on capturing windows using EnumWindow and all of that. I'm familiar with callbacks, but a little confused on how to use them.

I'm also considering using pyWinAuto's SendKeys.

I do realize there are programs like X-Mouse Button Control that can do all of this for me, but I'm learning and this would be a fun exercise.


Solution

  • I would recommend using PyAutoit for this, it's fairly straightforward to use and it usually works well. Steps to install the package and a simple example can be found here :

    https://pypi.python.org/pypi/PyAutoIt/0.3