Dependency package
import time import pyautogui import pyperclip import os import psutil from import Application
Sleep:
(1)
Mouse Events:
(100, 100, duration=0.25) (100, 100, duration=0.25) (10,10) # Click the specified position with the mouse, the default PRIMARY key(10,10,button='left') # Click the left button(1000,300,button='right') # Right-click(1000,300,button='middle') # Click the middle key ## For more convenience, the following function wraps the click, and does not need to pass the argument button(10,10) # Click the left button(10,10) # Right-click(10,10) # Click the middle key # Double-click the mouse(10,10) # Three-click the mouse(10,10) # Press & release() # Press the mouse() # Mouse release #Drag the mouse(x, y) Absolute location (x, y) Relative position # Scroll the mouse Scroll occurs at the current position of the mouse. Passing a positive integer means scrolling up, passing a negative integer means scrolling down.(-100) (100) # Scroll to the right 100(-100) # Scroll left by 100 # key operation press('enter', 5) # Double-click 5 times to enter# Press & release('A') : Simulation button press; ('A') : Simulate key release; ('ctrl') ('c') ('c') ('ctrl') ('ctrl', 'c')
Kill the process:
def kill_process(process_name): for proc in psutil.process_iter(['pid', 'name']): if ['name'] == process_name: try: () print(f"Process {process_name} with PID {['pid']} has been terminated.") except : print(f"Process {process_name} with PID {['pid']} no longer exists.") except : print(f"Access denied to terminate process {process_name}.") # usekill_process('')
Get the names of all windows:
titles = () print("titles: ", titles)
Display window:
def make_window_visible(title): try: # Try to connect to a running application app = Application(backend="uia").connect(title=title, timeout=10) window = (title=title) # Make sure the window is visible and in the front if not window.is_active(): window.set_focus() # Set focus, which usually brings the window to the foreground if not window.is_visible(): () # Show window (if it is minimized or hidden) print(f"Window '{title}' has been made visible and active.") except Exception as e: print(f"Failed to make window '{title}' visible: {e}") # make_window_visible('WeChat')
Find elements based on the image:
# Only one is returned heredef close_dialog(): try: close_icon_center = ('close_icon.png', grayscale=True, confidence=0.9) (0.01) print("Box Close Icon-Coordinates:", close_icon_center) if close_icon_center: (close_icon_center.x, close_icon_center.y) (0.01) except as ee: print("No pop-up box close icon found") # Multiple operationsdown_select_icon_centers = list(('down_select_icon.png', grayscale=True, confidence=0.9)) print("Pull down arrow length len:", len(down_select_icon_centers)) ((down_select_icon_centers[1]).x, (down_select_icon_centers[1]).y)
Enter text:
# This may be affected by the input method() def paste_str(str1): (str1) ('ctrl', 'v') # ('') # Reset the pasteboard content to empty # () This is paste
Open the app:
# OpenApplication().start("D:/Program Files/AliWorkbench/") # showmake_window_visible('Qianniu Workbench') # Get window according to window name and maximizechat_window = ('Qianniu Workbench')[0] chat_window.maximize() # () # Maximize # () # Minimize # () # If it is maximum/minimized, it will return to normal state # ()
This is the article about the implementation of Windows automation Python pyautogui RPA operation. For more related Python pyautogui RPA operation content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!