随机位置屏幕切换点击

import pymouse
from time import sleep
import random


def clicks(time):
    randoms = random.randint(0, len(lists) - 2)
    sleep(time)
    if m.position() not in lists: # 鼠标移动后停止切换
        print("break:", m.position())
        return True
    a = m.position()
    print(f"{time}s-第{randoms + 1}框:{a}")
    m.click(*lists[randoms])


def main():
    i = True
    while True:
        if i: # 判断是否为初始值
            m.click(*initial)
            i = False
        randoms = random.randint(2, 7) # 随机X秒后执行 
        if clicks(randoms):  
            break


initial = (1116, 472) # 初始值,用于在idea运行后自动切换窗口
m = pymouse.PyMouse()
lists = [(654, 207), (660, 263), (647, 320), (655, 377), initial] # 需要点击的位置坐标
main()

# if __name__ == '__main__':
#     while True:
#         m = pymouse.PyMouse()
#         a = m.position()
#         sleep(1)
#         print(a)

你可能感兴趣的:(python,开发语言)