I have an old accounting program that doesn't have an API or web interface. Is it possible to use Python to automate mouse clicks and keyboard inputs to enter data into this desktop application? I've looked into PyAutoGUI but I'm worried about the script breaking if a window moves slightly
3 answers
PyAutoGUI is great for simple tasks, but for legacy Windows apps, you should check out Pywinauto. Unlike PyAutoGUI, which relies on screen coordinates, Pywinauto "talks" to the actual backend controls of the window. This means it can find a button by its name or ID, so it won't matter if the window is moved or resized. If the app is very old or "non-standard," you can use the image recognition feature in PyAutoGUI to locate icons on the screen, providing a hybrid approach to Robotic Process Automation.
If you use image recognition, how do you handle different screen resolutions or "dark mode" settings that might change how those icons appear to the script?
It’s basically building your own mini-RPA bot. Python is much more flexible for this than expensive enterprise software like UiPath for smaller, targeted tasks.
Totally, Daniel. I’ve saved my company thousands in licensing fees by just writing custom Python automation scripts for these simple back-office chores.
That’s a common hurdle, Richard. The trick is using the confidence parameter in the locateOnScreen function. By setting it to around 0.8 or 0.9, you allow for slight pixel variations. Also, always try to use grayscale matching where possible. However, the real pro tip is to force the legacy application to open in a fixed resolution and standard theme before the automation starts to ensure consistent results every time.