analitics

Pages

Showing posts with label pyautogui. Show all posts
Showing posts with label pyautogui. Show all posts

Wednesday, October 18, 2023

Python 3.12.0 : PyAutoGUI example.

PyAutoGUI lets your Python scripts control the mouse and keyboard to automate interactions with other applications.
Make sure the modal dialog window is active and the desired text is visible before running the script.
This script waits for the user to activate the modal dialog window (for example, by clicking on the dialog window) and then moves the cursor to the coordinates of the label in the dialog window.
Copies the selected text to the clipboard using the classic Ctr and C keys.
Let's see the source code that does this.
import pyautogui
import time

# Display a short notification to prompt the user to activate the modal dialog window
print("Please activate the modal dialog window.")

# Wait for the user to activate the modal dialog window (you can click in the dialog window)
time.sleep(10) # Wait 10 seconds or enough time to activate the window

# Get the coordinates where you want to read the text on the label
x_label = 200 # Replace with the correct x coordinates
y_label = 300 # Replace with the correct y coordinates

# Move the mouse cursor to the coordinates of the label
pyautogui.moveTo(x_label, y_label)

# Select the text in the label using the mouse
pyautogui.dragTo(x_label + 200, y_label, duration=1) # Substitute the appropriate coordinates and duration

# Copies the selected text to the clipboard
pyautogui.hotkey("ctrl", "c")

# You can use the clipboard to access the read text
import clipboard
text_copied = clipboard.paste()