asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.45k stars 1.26k forks source link

How to check if .typewrite() failed or read the text you tried to insert? #859

Open pLazyN opened 5 months ago

pLazyN commented 5 months ago

Hello,

thanks for the great project, I have used pyautogui successfully for several years now to automate inputs for applications without an API or any other way to interact.

Recently I ran into a problem with a script that was used without any issues in the past. It reads a value from a text file, navigates to the corresponding input box and uses .typewrite() to input the value. Then it switches back to another tab within the application and opens a message box to show which value was inserted (for the user to double check).

The script runs as normal, the message box shows the right value but when looking at the tab where the value is inserted you see it failed. I still contains the previous value.

While I still try to figure out the cause, I would like to add a safety feature that checks if .typewrite() actually inserted the value. Since I cannot use the screenshot function I thought maybe I can use hotkey "ctrl + c" after typewrite. But there is no function within pyautogui to read from the clipboard, right? Or any other read function for that matter.

How would you handle typewrite for text inputs?