[Python] Get the mouse position and click automatically

1. Get the mouse position

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. Move the mouse and click

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()

Guess you like

Origin blog.csdn.net/qq_35632833/article/details/108761531