【python】获取鼠标位置并自动点击

1. 获取鼠标位置

import os,time
import pyautogui as pag
try:
    while True:
            print("Press Ctrl-C to end")
            x,y = pag.position() #返回鼠标的坐标
            posStr="Position:"+str(x).rjust(4)+','+str(y).rjust(4)
            print (posStr)#打印坐标
            time.sleep(0.2)
            os.system('cls')#清楚屏幕
except  KeyboardInterrupt:
    print ('end....')

2. 移动鼠标并点击

import time
import pyautogui

x,y = pyautogui.position() #返回鼠标的坐标
posStr="Position:"+str(x).rjust(4)+','+str(y).rjust(4)
print (posStr)#打印坐标

x, y = 1000, 534  # 鼠标需要移动到的位置
num_seconds = 2  # 将鼠标移动到指定坐标的间隔时间

time.sleep(8)  # 延迟8秒
pyautogui.moveTo(x, y, duration=num_seconds)

time.sleep(3)  # 延迟3秒
i = 60

while i:
    i -= 1
    time.sleep(5)
    pyautogui.click()

猜你喜欢

转载自blog.csdn.net/qq_35632833/article/details/108761531
今日推荐