You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB
Python

import logging
import time
import winsound
from airtest.core.api import *
from threading import Thread
import keyboard
import pynput
import pyautogui
from screen_shot import screen_shot_mss, show
import random
logger = logging.getLogger("airtest")
logger.setLevel(logging.NOTSET)
IMAGE_SIZE = 25
IMAGE_X = 1180
IMAGE_Y = 1000
BLUE = Template("./blue.jpg", rgb=True)
RED = Template("./red.jpg", rgb=True, threshold=0.9)
YELLOW = Template("./yellow.jpg", rgb=True)
TARGET: Template = ...
IS_CLICK_E = False
def on_press(key):
global TARGET,IS_CLICK_E
try:
if key.char == "w":
if IS_CLICK_E:
pass
else:
print("切黄牌")
TARGET = YELLOW
elif key.char == "e":
IS_CLICK_E = True
time.sleep(random.randint(20, 50) / 1000)
keyboard.send("w")
TARGET = BLUE
print("切蓝牌")
except Exception as e:
pass
def listener_keyword():
print(f"开始监听键盘")
with pynput.keyboard.Listener(on_press=on_press) as listener:
listener.join()
def check_target():
print(f"开始监听屏幕")
global TARGET, IS_CLICK_E
while True:
time.sleep(random.randint(5, 10) / 1000)
if TARGET is not ...:
tmp_image_array = screen_shot_mss(IMAGE_SIZE, IMAGE_SIZE, IMAGE_X, IMAGE_Y)
if TARGET.match_in(tmp_image_array):
print("找到了")
winsound.Beep(400, 200)
time.sleep(random.randint(5, 10) / 1000)
keyboard.send("w")
time.sleep(random.randint(5, 10) / 1000)
keyboard.send("w")
TARGET = ...
IS_CLICK_E = False
if __name__ == "__main__":
winsound.Beep(800, 200)
Thread(target=listener_keyword).start()
time.sleep(1)
Thread(target=check_target).start()
time.sleep(2**16)