diff --git a/.gitignore b/.gitignore index 723ef36..be98a19 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +.tmp \ No newline at end of file diff --git a/G-series Lua API 参考文档.docx b/G-series Lua API 参考文档.docx new file mode 100644 index 0000000..6af534e Binary files /dev/null and b/G-series Lua API 参考文档.docx differ diff --git a/lol_script/1.png b/lol_script/1.png new file mode 100644 index 0000000..c1ce548 Binary files /dev/null and b/lol_script/1.png differ diff --git a/lol_script/10.png b/lol_script/10.png new file mode 100644 index 0000000..1d4b193 Binary files /dev/null and b/lol_script/10.png differ diff --git a/lol_script/11.png b/lol_script/11.png new file mode 100644 index 0000000..aa769de Binary files /dev/null and b/lol_script/11.png differ diff --git a/lol_script/12.png b/lol_script/12.png new file mode 100644 index 0000000..2e403ac Binary files /dev/null and b/lol_script/12.png differ diff --git a/lol_script/14.png b/lol_script/14.png new file mode 100644 index 0000000..fe62ab6 Binary files /dev/null and b/lol_script/14.png differ diff --git a/lol_script/15.png b/lol_script/15.png new file mode 100644 index 0000000..2c7f81c Binary files /dev/null and b/lol_script/15.png differ diff --git a/lol_script/16.png b/lol_script/16.png new file mode 100644 index 0000000..ed69172 Binary files /dev/null and b/lol_script/16.png differ diff --git a/lol_script/17.png b/lol_script/17.png new file mode 100644 index 0000000..1ac92e4 Binary files /dev/null and b/lol_script/17.png differ diff --git a/lol_script/18.png b/lol_script/18.png new file mode 100644 index 0000000..0f43341 Binary files /dev/null and b/lol_script/18.png differ diff --git a/lol_script/2.png b/lol_script/2.png new file mode 100644 index 0000000..6b8346e Binary files /dev/null and b/lol_script/2.png differ diff --git a/lol_script/3.png b/lol_script/3.png new file mode 100644 index 0000000..f0fcc67 Binary files /dev/null and b/lol_script/3.png differ diff --git a/lol_script/4.png b/lol_script/4.png new file mode 100644 index 0000000..ec57c05 Binary files /dev/null and b/lol_script/4.png differ diff --git a/lol_script/5.png b/lol_script/5.png new file mode 100644 index 0000000..adf9128 Binary files /dev/null and b/lol_script/5.png differ diff --git a/lol_script/6.png b/lol_script/6.png new file mode 100644 index 0000000..8ff383b Binary files /dev/null and b/lol_script/6.png differ diff --git a/lol_script/7.png b/lol_script/7.png new file mode 100644 index 0000000..71c068c Binary files /dev/null and b/lol_script/7.png differ diff --git a/lol_script/8.png b/lol_script/8.png new file mode 100644 index 0000000..be09d10 Binary files /dev/null and b/lol_script/8.png differ diff --git a/lol_script/9.png b/lol_script/9.png new file mode 100644 index 0000000..aa98caf Binary files /dev/null and b/lol_script/9.png differ diff --git a/lol_script/base.png b/lol_script/base.png new file mode 100644 index 0000000..2e715f9 Binary files /dev/null and b/lol_script/base.png differ diff --git a/lol_script/main.py b/lol_script/main.py new file mode 100644 index 0000000..ba86e06 --- /dev/null +++ b/lol_script/main.py @@ -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 \ No newline at end of file diff --git a/mouse/logitech.driver.dll b/mouse/logitech.driver.dll new file mode 100644 index 0000000..82a950b Binary files /dev/null and b/mouse/logitech.driver.dll differ diff --git a/mouse/logitech.py b/mouse/logitech.py new file mode 100644 index 0000000..cb78df0 --- /dev/null +++ b/mouse/logitech.py @@ -0,0 +1,107 @@ +import ctypes +import os +import time + +import pynput +import winsound + +try: + root = os.path.abspath(os.path.dirname(__file__)) + driver = ctypes.CDLL(f'{root}/logitech.driver.dll') + ok = driver.device_open() == 1 # 该驱动每个进程可打开一个实例 + if not ok: + print('Error, GHUB or LGS driver not found') +except FileNotFoundError: + print(f'Error, DLL file not found') + + +class Logitech: + + class mouse: + + """ + code: 1:左键, 2:中键, 3:右键 + """ + + @staticmethod + def press(code): + if not ok: + return + driver.mouse_down(code) + + @staticmethod + def release(code): + if not ok: + return + driver.mouse_up(code) + + @staticmethod + def click(code): + if not ok: + return + driver.mouse_down(code) + driver.mouse_up(code) + + @staticmethod + def scroll(a): + """ + a:没搞明白 + """ + if not ok: + return + driver.scroll(a) + + @staticmethod + def move(x, y): + """ + 相对移动, 绝对移动需配合 pywin32 的 win32gui 中的 GetCursorPos 计算位置 + pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple + x: 水平移动的方向和距离, 正数向右, 负数向左 + y: 垂直移动的方向和距离 + """ + if not ok: + return + if x == 0 and y == 0: + return + driver.moveR(x, y, True) + + class keyboard: + + """ + 键盘按键函数中,传入的参数采用的是键盘按键对应的键码 + code: 'a'-'z':A键-Z键, '0'-'9':0-9, 其他的没猜出来 + """ + + @staticmethod + def press(code): + + if not ok: + return + driver.key_down(code) + + @staticmethod + def release(code): + if not ok: + return + driver.key_up(code) + + @staticmethod + def click(code): + if not ok: + return + driver.key_down(code) + driver.key_up(code) + + +if __name__ == '__main__': # 测试 + winsound.Beep(800, 200) + + def release(key): + if key == pynput.keyboard.Key.end: # 结束程序 End 键 + winsound.Beep(400, 200) + return False + elif key == pynput.keyboard.Key.home: # 移动鼠标 Home 键 + winsound.Beep(600, 200) + # Logitech.mouse.move(100, 100) + with pynput.keyboard.Listener(on_release=release) as k: + k.join() diff --git a/poe.py b/poe.py new file mode 100644 index 0000000..60159ec --- /dev/null +++ b/poe.py @@ -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() diff --git a/pubg_caps.py b/pubg_caps.py new file mode 100644 index 0000000..96698e5 --- /dev/null +++ b/pubg_caps.py @@ -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() + + + + + + diff --git a/screen_shot.py b/screen_shot.py new file mode 100644 index 0000000..3b6d69d --- /dev/null +++ b/screen_shot.py @@ -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) + diff --git a/卡牌/blue.jpg b/卡牌/blue.jpg new file mode 100644 index 0000000..b1db9f5 Binary files /dev/null and b/卡牌/blue.jpg differ diff --git a/卡牌/red.jpg b/卡牌/red.jpg new file mode 100644 index 0000000..aeb5870 Binary files /dev/null and b/卡牌/red.jpg differ diff --git a/卡牌/yellow.jpg b/卡牌/yellow.jpg new file mode 100644 index 0000000..cfe0c54 Binary files /dev/null and b/卡牌/yellow.jpg differ diff --git a/卡牌/卡牌.py b/卡牌/卡牌.py new file mode 100644 index 0000000..763b78f --- /dev/null +++ b/卡牌/卡牌.py @@ -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) \ No newline at end of file