python3.7 特定时间间隔一直循环鼠标双击“我的电脑”图标
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 3 11:31:54 2019
@author: fern.xu
"""
import win32api
import win32gui
import win32con
import time
import ctypes
import sched
import os
import datetime
def click(x,y): #第二种
ctypes.windll.user32.SetCursorPos(x,y)
ctypes.windll.user32.mouse_event(2,0,0,0,0)
ctypes.windll.user32.mouse_event(4,0,0,0,0)
ctypes.windll.user32.mouse_event(2,0,0,0,0)
ctypes.windll.user32.mouse_event(4,0,0,0,0)
'''
def timer(n):
'''''
每n秒执行一次
'''
while True:
print(time.strftime('%Y-%m-%d %X',time.localtime()))
click(40,23) # 此处为要执行的任务
time.sleep(n)
#timer(2)
'''
# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
# 第二个参数以某种人为的方式衡量时间
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
# 安排inc秒后再次运行自己,即周期运行
schedule.enter(inc, 0, perform_command, (cmd, inc))
#os.system(cmd)
click(40,23)
quit()
def timming_exe(cmd, inc = 60):
# enter用来安排某事件的发生时间,从现在起第n秒开始启动
schedule.enter(inc, 0, perform_command, (cmd, inc))
# 持续运行,直到计划时间队列变成空为止
schedule.run()
print("show time after 10 seconds:")
timming_exe("echo %time%", 20)