-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
可以增加一个定时执行吗 #280
Comments
都提供命令行执行方式了,自己做计划任务就行了吧 |
给你提供一个插件 from assets.plugins.Extension import *
import time
import datetime
from loguru import logger
import win32gui
class WaitExtension(Extension):
def __init__(self, runtimes, speed, thd=None, swap=None):
super().__init__(runtimes, speed, thd, swap)
def onrunbefore(self, event, currentindex):
if event.event_type == "WT":
# [10,"WT","time",1716344132],
if event.message == 'time':
try:
start_timestamp = event.action
date = datetime.datetime.fromtimestamp(start_timestamp)
custom_format = "%Y-%m-%d %H:%M:%S" # 自定义格式:年-月-日 时:分:秒
formatted_date = date.strftime(custom_format)
logger.info('Script start at %s' % formatted_date)
# 获取当前时间戳
current_timestamp = time.time()
# 计算需要等待的秒数
seconds_to_wait = max(0, start_timestamp - current_timestamp)
# 等待到达目标时间戳
time.sleep(seconds_to_wait)
except Exception as e:
logger.warning('Time stamp format error.')
elif event.message == 'color wait':
# 如果为某个color时,则一直等待
# [200, "WT", "color wait", [960, 1220], [255, 255, 255]],
try:
logger.debug("Color wait: ", event.addon)
x, y = event.action
while True:
color_given = tuple(event.addon)
pixel_color = self.get_pixel_color(x,y)
if color_given == pixel_color:
time.sleep(0.2)
else:
break
logger.debug("Color changed, script continues to run.")
except Exception as e:
logger.warning('Color wait error: ', e)
else:
logger.warning('Unknown time event:%s' % self.message)
# 等待事件,已执行,后续不需要执行
return False
return True
def get_pixel_color(self, x, y):
# 获取屏幕设备上下文
hdc = win32gui.GetDC(0)
# 获取指定点的颜色值
color = win32gui.GetPixel(hdc, x, y)
# 释放设备上下文
win32gui.ReleaseDC(0, hdc)
r, g, b = color & 0xff, (color >> 8) & 0xff, (color >> 16) & 0xff
# 返回颜色值
return (r, g, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: