Search code examples
pythonpywinauto

How to make pywinauto work in background?


I want to use pywinauto in background to avoid interference with my work.

As the automation begins, I need to stop all my work.

How to make pywinauto operate silently in background?


Solution

  • It's not always possible to make everything silently. Some methods don't require real clicks, but you have to re-write the script anyway.

    click_input and derived methods can work with focused window only as well as type_keys method. Some other methods may bring the window into focus (especially for "uia" backend) depending on their app side implementation.

    One possible solution is using virtual or remote machine, but you have to copy your script to this VM and prepare Python environment there. For further guidance I would recommend reading pywinauto's Remote Execution Guide.

    Good background script example for backend="win32" had been posted on StackOverflow few years ago (Notepad++ automation). Just aligned it with pywinauto==0.6.5: https://stackoverflow.com/a/32847266/3648361