赞
踩
pyautogui
datetime
threading
interval
使用管理员权限运行代码,非常重要,否者pyautogui操作无效
- import pyautogui as pg
- import datetime
- import threading
- ##获取按键位置
- # while True:
- # print(pg.position())
- #定义需要的操作,这里以单击某个按键为例
- def fun():
- pg.click(x=648, y=535)
- print('ok')
- # 获取现在时间
- now_time = datetime.datetime.now()
- # 获取x点时间
- next_time = datetime.datetime.strptime(str(2022) + "-" + str(5) + "-" + str(18) + " 09:00:00",
- "%Y-%m-%d %H:%M:%S")
- # 获取距离x点时间,单位为秒
- timer_start_time = (next_time - now_time).total_seconds()
- print(timer_start_time)
- # 定时器,参数为(多少时间后执行,单位为秒,执行的方法)
- timer = threading.Timer(timer_start_time, fun)
- timer.start()
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- import pyautogui as pg
- import datetime
- import threading
- from interval import Interval
- import time
- while True:
- # 当前时间
- now_localtime = time.strftime("%H:%M:%S", time.localtime())
- # 当前时间(以时间区间的方式表示)
- now_time = Interval(now_localtime, now_localtime)
- print(now_time)
-
- time_interval = Interval("09:00:00", "09:01:00")
- print(time_interval)
-
- if now_time in time_interval:
- pg.click(x=648,y=535)
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。