# -*- coding: utf-8 -*- # 利用pyautogui模块实现鼠标移动 单击 拖动 滚动 等操作 import time import pyautogui # 移动鼠标 def demo1(): # duration=1 移动时间持续1秒 pyautogui.moveTo(1000, 200, duration=1) pyautogui.move(0, 300, duration=2) # 获取鼠标的坐标位置 def demo2(): time.sleep(1) print(pyautogui.position()) def demo3(): time.sleep(1) pyautogui.click(300, 300, clicks=2) time.sleep(1) # 单击鼠标右键 pyautogui.click(button='right') # 单击鼠标左键 pyautogui.click(button='left') # 双击 pyautogui.doubleClick() # 左击 pyautogui.leftClick() # 右击 pyautogui.rightClick() # 按下鼠标左键 pyautogui.mouseDown(4704, 542) # 释放坐标左键 pyautogui.mouseUp(4704, 542) # 拖动鼠标 """以打开记事本软件为案例 拖动鼠标的过程总共分为三步 1 按住鼠标左键不放 2 将记事本窗口拖到指定的位置 3 释放鼠标左键""" def demo4(): pyautogui.dragTo(516, 42, duration=1, button='left') pyautogui.drag(600, 500, duration=1, button='left') pyautogui.mouseUp() # 滚动鼠标 def demo5(): time.sleep(1) pyautogui.scroll(1000) pyautogui.scroll(-100) pyautogui.scroll(100, x=200, y=300) # demo1() # demo2() # demo3() # demo4() demo5()
标签:pyautogui,控制,鼠标,左键,time,duration,操作,def From: https://www.cnblogs.com/zhaoyiguang/p/16749803.html