添加脚本
@ -1 +1,2 @@
|
||||
.idea
|
||||
.tmp
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 974 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 922 B |
After Width: | Height: | Size: 1020 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 890 B |
After Width: | Height: | Size: 844 B |
After Width: | Height: | Size: 879 B |
After Width: | Height: | Size: 942 B |
After Width: | Height: | Size: 966 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 482 B |
@ -0,0 +1,99 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from threading import Thread
|
||||
import numpy as np
|
||||
import cv2
|
||||
from airtest.core.cv import Template
|
||||
import pyautogui
|
||||
from pynput import mouse
|
||||
|
||||
from mouse.logitech import Logitech
|
||||
from screen_shot import screen_shot_mss, show, save_image
|
||||
|
||||
logger = logging.getLogger("airtest")
|
||||
logger.setLevel(logging.NOTSET)
|
||||
|
||||
ENEMY_X = 5
|
||||
ENEMY_Y = 15
|
||||
CHAMPION_H = 190
|
||||
CHAMPION_W = 130
|
||||
|
||||
GLOBAL_POS_LIS = []
|
||||
|
||||
|
||||
def is_some_color(s_array):
|
||||
# 查找是否有30个像素是暗红色
|
||||
|
||||
# 检查颜色条件
|
||||
condition = ((s_array[:, :, 2] > 50) & (s_array[:, :, 2] < 70) &
|
||||
(s_array[:, :, 1] > 0) & (s_array[:, :, 1] < 20) &
|
||||
(s_array[:, :, 0] > 0) & (s_array[:, :, 0] < 20))
|
||||
|
||||
# 计算满足条件的像素数量
|
||||
num_matching_pixels = np.sum(condition)
|
||||
|
||||
# 判断是否有30个像素满足条件
|
||||
return num_matching_pixels >= 30
|
||||
|
||||
|
||||
left_button_pressed = False
|
||||
def mouse_handle():
|
||||
while True:
|
||||
time.sleep(0.2)
|
||||
if left_button_pressed:
|
||||
now_x, now_y = pyautogui.position()
|
||||
if GLOBAL_POS_LIS:
|
||||
x, y = GLOBAL_POS_LIS[0]
|
||||
|
||||
move_x = x - now_x
|
||||
move_y = y - now_y
|
||||
print(move_x, move_y)
|
||||
Logitech.mouse.move(move_x, move_y)
|
||||
|
||||
|
||||
def listen():
|
||||
def on_click(x, y, button, pressed):
|
||||
global left_button_pressed
|
||||
if button == mouse.Button.left:
|
||||
left_button_pressed = pressed
|
||||
|
||||
listener = mouse.Listener(on_click=on_click)
|
||||
listener.start()
|
||||
|
||||
if __name__ == '__main__':
|
||||
Thread(target=mouse_handle).start()
|
||||
Thread(target=listen).start()
|
||||
|
||||
base_t = Template("./base.png")
|
||||
lower_gray = np.array([70, 70, 70])
|
||||
upper_gray = np.array([120, 120, 120])
|
||||
while True:
|
||||
tmp_pos_lis = []
|
||||
now_screen = screen_shot_mss(2200, 900, 180, 90)
|
||||
mask = cv2.inRange(now_screen, lower_gray, upper_gray)
|
||||
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
|
||||
for contour in contours:
|
||||
x, y, w, h = cv2.boundingRect(contour)
|
||||
if w > 20 and h < 5:
|
||||
s = now_screen[y - 30:y + 30, x - 30:x + 30]
|
||||
if s.any():
|
||||
cv2.rectangle(now_screen, (x - 30, y - 30), (x + 30, y + 30), (0, 255, 0), thickness=2)
|
||||
pos = base_t.match_in(s)
|
||||
if pos:
|
||||
if is_some_color(s):
|
||||
# cv2.rectangle(now_screen, (x, y), (x + 80, y + 150), (0, 255, 0), thickness=2)
|
||||
# cv2.rectangle(now_screen, (x-30, y-30), (x+50, y+50), (0, 255, 0), thickness=2)
|
||||
pos_x, pos_y = pos
|
||||
|
||||
# 计算pos在屏幕的 坐标
|
||||
s_x = 180 + x - 30 + pos_x
|
||||
s_y = 90 + y - 30 + pos_y
|
||||
|
||||
# 加上一些坐标得到人物的主体大概部位
|
||||
p_x = s_x + 55
|
||||
p_y = s_y + 115
|
||||
tmp_pos_lis.append([p_x, p_y])
|
||||
# show(now_screen)
|
||||
GLOBAL_POS_LIS = tmp_pos_lis
|
@ -0,0 +1,95 @@
|
||||
import time
|
||||
|
||||
from pynput import keyboard, mouse
|
||||
from pynput.mouse import Button
|
||||
import threading
|
||||
|
||||
control = keyboard.Controller()
|
||||
|
||||
IS_LEFT_DOWN = True
|
||||
IS_RIGHT_DOWN = True
|
||||
IS_START = False
|
||||
IS_FLAG_T = time.time()
|
||||
|
||||
def on_press(key):
|
||||
global IS_LEFT_DOWN, IS_RIGHT_DOWN, IS_START
|
||||
try:
|
||||
if key.char == "=":
|
||||
IS_START = not IS_START
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
def on_click(x, y, button: Button, pressed):
|
||||
global IS_LEFT_DOWN, IS_RIGHT_DOWN, IS_START, IS_FLAG_T
|
||||
|
||||
if "left" in str(button):
|
||||
if pressed:
|
||||
print("鼠标左键按下")
|
||||
IS_LEFT_DOWN = True
|
||||
else:
|
||||
print("鼠标左键释放")
|
||||
IS_FLAG_T = time.time()
|
||||
IS_LEFT_DOWN = False
|
||||
if "right" in str(button):
|
||||
if pressed:
|
||||
print("鼠标右键按下")
|
||||
IS_RIGHT_DOWN = True
|
||||
else:
|
||||
print("鼠标右键释放")
|
||||
IS_RIGHT_DOWN = False
|
||||
|
||||
|
||||
def listener_mouse():
|
||||
with mouse.Listener(on_click=on_click) as listener:
|
||||
listener.join()
|
||||
|
||||
def listener_keyword():
|
||||
with keyboard.Listener(on_press=on_press) as listener:
|
||||
listener.join()
|
||||
|
||||
def down_w():
|
||||
return
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
print(IS_LEFT_DOWN, IS_RIGHT_DOWN)
|
||||
if IS_LEFT_DOWN or IS_RIGHT_DOWN:
|
||||
...
|
||||
else:
|
||||
if IS_START:
|
||||
# 鼠标左键释放后的0.5s 不做任何处理
|
||||
if time.time() - IS_FLAG_T < 0.5:
|
||||
continue
|
||||
control.press("w")
|
||||
control.release("w")
|
||||
control.press("w")
|
||||
control.release("w")
|
||||
|
||||
def eat():
|
||||
f = 9.5
|
||||
|
||||
tmp = True
|
||||
last_t = time.time()
|
||||
while True:
|
||||
time.sleep(0.01)
|
||||
if IS_START:
|
||||
t = time.time()
|
||||
if t - last_t > f:
|
||||
last_t = t
|
||||
if tmp:
|
||||
control.press("1")
|
||||
control.release("1")
|
||||
else:
|
||||
control.press("2")
|
||||
control.release("2")
|
||||
tmp = not tmp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
threading.Thread(target=listener_mouse).start()
|
||||
threading.Thread(target=listener_keyword).start()
|
||||
threading.Thread(target=eat).start()
|
||||
threading.Thread(target=down_w).start()
|
@ -0,0 +1,51 @@
|
||||
from win32api import GetKeyState
|
||||
from pynput.mouse import Listener
|
||||
from pynput.keyboard import Key, Controller
|
||||
import time
|
||||
|
||||
# 键盘控制控件
|
||||
ctr = Controller()
|
||||
|
||||
|
||||
def key_up(key, t=0.1):
|
||||
# 按下按键
|
||||
ctr.press(key)
|
||||
time.sleep(t)
|
||||
|
||||
|
||||
def key_down(key, t=0.1):
|
||||
# 松开按键
|
||||
ctr.release(key)
|
||||
time.sleep(t)
|
||||
|
||||
|
||||
def is_caps():
|
||||
# 监听大小写
|
||||
return GetKeyState(20)
|
||||
|
||||
|
||||
def on_scroll(x, y, dx, dy):
|
||||
# 监听鼠标滚轮, 并检测大小写
|
||||
# print('Scrolled {0}'.format((x, y)))
|
||||
if dy == 1:
|
||||
print("关掉大写")
|
||||
if is_caps():
|
||||
key_up(Key.caps_lock)
|
||||
key_down(Key.caps_lock)
|
||||
|
||||
elif dy == -1:
|
||||
print("开启大写")
|
||||
if not is_caps():
|
||||
key_up(Key.caps_lock)
|
||||
key_down(Key.caps_lock)
|
||||
|
||||
|
||||
# 连接事件以及释放
|
||||
with Listener(on_scroll=on_scroll) as listener:
|
||||
listener.join()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,118 @@
|
||||
import win32con
|
||||
import win32api
|
||||
import win32gui
|
||||
import win32ui
|
||||
from mss import mss
|
||||
import cv2
|
||||
import numpy as np
|
||||
import time
|
||||
|
||||
ScreenX = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
|
||||
ScreenY = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
|
||||
|
||||
ALL_S_CNT = 0
|
||||
ALL_S_T = 0.0
|
||||
|
||||
ScreenShot = mss()
|
||||
|
||||
|
||||
def save_image(img, filename):
|
||||
# 保存图像
|
||||
cv2.imwrite(filename, img)
|
||||
|
||||
|
||||
def show(img):
|
||||
cv2.imshow('window', img)
|
||||
cv2.waitKey(1)
|
||||
|
||||
|
||||
|
||||
def get_all_hwnd():
|
||||
hwnd_title_lis = []
|
||||
def _callback(hwnd, mouse):
|
||||
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
|
||||
hwnd_title_lis.append((hwnd, win32gui.GetWindowText(hwnd)))
|
||||
win32gui.EnumWindows(_callback, 0)
|
||||
return hwnd_title_lis
|
||||
|
||||
|
||||
def screen_shot_mss(width, high, left=None, top=None):
|
||||
global ALL_S_T, ALL_S_CNT
|
||||
|
||||
start = time.time()
|
||||
if left and top:
|
||||
pass
|
||||
else:
|
||||
left = int(ScreenX / 2 - width/2)
|
||||
top = int(ScreenY / 2 - high/2)
|
||||
screenshot = ScreenShot.grab((left, top, left+width, top+high))
|
||||
img = cv2.cvtColor(np.array(screenshot), cv2.COLOR_BGRA2BGR)
|
||||
|
||||
ALL_S_CNT += 1
|
||||
ALL_S_T += (time.time() - start) * 1000
|
||||
print(end='\r')
|
||||
print(f"平均截图用时: {round(ALL_S_T / ALL_S_CNT, 2)}ms", end="", flush=True)
|
||||
return img
|
||||
|
||||
|
||||
def screen_shot_win32(size, title_info):
|
||||
global title, ALL_S_T, ALL_S_CNT
|
||||
try:
|
||||
if title != "":
|
||||
hwnd = win32gui.FindWindow(None, title)
|
||||
if hwnd == 0:
|
||||
print(f'{title}不存在,请重新检查窗口名字是否正确。')
|
||||
start = time.time()
|
||||
|
||||
hwndDC = win32gui.GetWindowDC(hwnd)
|
||||
mfcDC = win32ui.CreateDCFromHandle(hwndDC)
|
||||
saveDC = mfcDC.CreateCompatibleDC()
|
||||
saveBitMap = win32ui.CreateBitmap()
|
||||
|
||||
left = int(ScreenX / 2 - size / 2)
|
||||
top = int(ScreenY / 2 - size / 2)
|
||||
x, y, w, h = (left, top, size, size)
|
||||
saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
|
||||
saveDC.SelectObject(saveBitMap)
|
||||
|
||||
saveDC.BitBlt((0, 0), (w, h), mfcDC, (x, y), win32con.SRCCOPY)
|
||||
signe_ints_array = saveBitMap.GetBitmapBits(True)
|
||||
img = np.frombuffer(signe_ints_array, dtype='uint8')
|
||||
img.shape = (h, w, 4)
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
|
||||
|
||||
win32gui.DeleteObject(saveBitMap.GetHandle())
|
||||
saveDC.DeleteDC()
|
||||
mfcDC.DeleteDC()
|
||||
|
||||
ALL_S_CNT += 1
|
||||
ALL_S_T += (time.time() - start) * 1000
|
||||
print(end='\r')
|
||||
print(f"平均截图用时: {round(ALL_S_T / ALL_S_CNT, 2)}ms", end="", flush=True)
|
||||
return img
|
||||
except Exception as e:
|
||||
print(e)
|
||||
all_title_lis = get_all_hwnd()
|
||||
title_lis = []
|
||||
for title_item in all_title_lis:
|
||||
if title_info in title_item[1]:
|
||||
title = title_item[1]
|
||||
title_lis.append(title_item[1])
|
||||
else:
|
||||
print(f"没有找到对应的title, all title: {title_lis}")
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f"所有的窗口: {[i[1] for i in get_all_hwnd()]}")
|
||||
while True:
|
||||
time.sleep(1)
|
||||
img_array = screen_shot_mss(25, 1180, 1000)
|
||||
# img_array = screen_shot_win32(25, "Client")
|
||||
|
||||
try:
|
||||
show(img_array)
|
||||
save_image(img_array, f"./tmp/{ALL_S_CNT}.jpg")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,77 @@
|
||||
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)
|