控制鼠标和键盘模块-pynput

Zss 发表于:

自动控制鼠标和键盘的一个模块

朋友需要控制鼠标键盘来挂机一个党员考试,需要阅读一定的时长才能考试,所以模拟鼠标和键盘来挂机

#coding:utf-8
from pynput.mouse import Button, Controller
import time 
 
 
def task(info):
    mouse.position = (0,0)
    mouse.move(info[0],info[1])
    mouse.click(Button.left,2)
        
    for i in range(info[2]):
        try:
            #xiayiye
            mouse.position = (0,0)
            mouse.move(768,54)
            mouse.click(Button.left,1)
            print '(%d)'%i
            time.sleep(300)
        except:
            time.sleep(60)
            print "fail",i

    #退出
    mouse.position = (0,0)
    mouse.move(603,55)
    mouse.click(Button.left,1)
    time.sleep(2)

    #必修课
    mouse.position = (0,0)
    mouse.move(100,288)
    mouse.click(Button.left,1)

    #下一页
    mouse.position = (0,0)
    mouse.move(397,522)
    mouse.click(Button.left,1)
    time.sleep(2)

if __name__ == '__main__':
    mouse = Controller()
    time.sleep(3)
    #(kebenweizhi,yemashu)
    task_list=[(829,307,150),(829,341,150),(829,375,150),(829,403,45),(829,438,120),(829,472,120)]


    for i in task_list:
        task(i)
        time.sleep(2)