定时进行鼠标键盘操作
2020-06-02 本文已影响0人
EZ
微信抢座位太难了,超微助手也可以定时发送微信消息,需要购买。选择使用pynout
直接模拟鼠标键盘事件。
datatime 模块需要继续学习,
import time
import datetime
import tqdm
from pynput import mouse,keyboard
from pynput.keyboard import Key
m_keyboard = keyboard.Controller()
m_mouse = mouse.Controller()
#输入消息确认
print('请将将需要发送的信息输入到发送框')
while True:
confirm = input('如果消息已编写请输入:ok ')
if confirm in ['ok','OK']:
print('消息已确认输入')
break
else:
print('请在输入框输入消息并确认')
#确定操作时间
now1 = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') #input time
print("请输入发送时间,格式如下\n",now1," 即年-月-日-时-分-秒")
mytime = input("消息发送时间: ") #调试 判断 时间到达的时间,应设置整分钟,秒数为0
my_time = mytime + "-000000"
#确定操作位置
print('请在5s内将鼠标移动至发送框')
time.sleep(5)
print('当前鼠标位置为:{}'.format(m_mouse.position))
m_mouse.position = m_mouse.position #重新设置鼠标位置
m_mouse.click(mouse.Button.left,1) #提前将光标移动至目标位置
time.sleep(1) #需要间隔
print('请不要操作鼠标')
#打印进度
my_time_y = int(my_time.split('-')[0])
my_time_m = int(my_time.split('-')[1])
my_time_d = int(my_time.split('-')[2])
my_time_h = int(my_time.split('-')[3])
my_time_min = int(my_time.split('-')[4])
my_time_s = int(my_time.split('-')[5])
my_time_ms = int(my_time.split('-')[6])
my_time_int = datetime.datetime(my_time_y,
my_time_m,
my_time_d,
my_time_h,
my_time_min,
my_time_s,
my_time_ms)
my_time_int = my_time_int - datetime.timedelta(microseconds=9000) #按需求调整提前的时间,微秒
print('调整后的预计发送时间:',my_time_int)
now_time_process = datetime.datetime.now() #process now time
print('当前时间为:',now_time_process)
left_time = (my_time_int-now_time_process).seconds
#print(left_time)
#left_time = int(left_time //0.5) - 2 #提前2秒结束进度报告,这个不是距发送时间的时间,是进度刷新次数
print('距发送时间还有 ',str(left_time),' s')
print('\n','='*20,'\n','正在等待到达发送时间\n','='*20)
print("当前剩余时间约为")
left_time_list = [str(i+1) for i in range(left_time)]
left_time_list.reverse()
process_time = (left_time - 3)/left_time #打印进度需要的时间
for i in left_time_list:
print(i,end = "->")
time.sleep(process_time)
#提前4s,后续进程需要时间
#循环查看时间
while True:
now = datetime.datetime.now() #f为毫秒
if now > my_time_int: #与提前的时间比较
m_keyboard.press(Key.enter) #判断时间与按键后时间 极度一致
print('\n按enter时间为:',datetime.datetime.now())
m_keyboard.release(Key.enter)
print('松开enter时间为:',datetime.datetime.now())
print('按键时间为:',datetime.datetime.now()) #也不是准确的按键时间,只是请求返回的时间
#测试了下,多次请求时间,请求需要的时间很短 ,可能是键盘事件需要时间
print("判断时间为",now)
break