最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python開發(fā)游戲自動(dòng)化后臺(tái)腳本的實(shí)現(xiàn)

 更新時(shí)間:2022年01月19日 10:34:20   作者:Yaadon  
本文主要介紹了Python開發(fā)游戲自動(dòng)化后臺(tái)腳本的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言

前段時(shí)間沉迷豬場(chǎng)一夢(mèng)江湖,由于實(shí)在太肝便萌生出用腳本做日常的想法,寫了第一個(gè)test.py,隨著后來各種功能的逐步添加,腳本也從前臺(tái)變成了支持后臺(tái)靜默運(yùn)行,功能漸漸完善,包括了常用的

1.鼠標(biāo)左鍵單擊指定坐標(biāo)
2.識(shí)別并單擊指定圖像
3.識(shí)別圖像中文字
4.后臺(tái)截取程序畫面以供識(shí)別
5.鼠標(biāo)滾輪上下滾動(dòng)
6.鼠標(biāo)左鍵范圍點(diǎn)擊以防檢測(cè)
7.程序中的鍵盤控制
8.程序中字符的輸入

說明

獲取窗口句柄

尋找標(biāo)題為title的窗口,激活該窗口并置于x_coor, y_coor處,title可利用visual studio的spy++.exe查看;SWP_NOSIZE指定了窗口大小不變

def get_winds(self, title: str):
? ? """
? ? @description : 獲取游戲句柄 ,并把游戲窗口置頂并激活窗口
? ? ---------
? ? @param : 窗口名
? ? -------
? ? @Returns : 窗口句柄
? ? -------
? ? """
? ? # self.__handle = win32gui.FindWindowEx(0, 0, "Qt5QWindowIcon", "MuMu模擬器")
? ? self.__handle = windll.user32.FindWindowW(None, title)
? ? self.__classname = win32gui.GetClassName(self.__handle)
? ? # print(self.__classname)
? ? if self.__classname == 'Qt5QWindowIcon':
? ? ? ? self.__mainhandle = win32gui.FindWindowEx(self.__handle, 0, "Qt5QWindowIcon", "MainWindowWindow")
? ? ? ? # print(self.__mainhandle)
? ? ? ? self.__centerhandle = win32gui.FindWindowEx(self.__mainhandle, 0, "Qt5QWindowIcon", "CenterWidgetWindow")
? ? ? ? # print(self.__centerhandle)
? ? ? ? self.__renderhandle = win32gui.FindWindowEx(self.__centerhandle, 0, "Qt5QWindowIcon", "RenderWindowWindow")
? ? ? ? # print(self.__renderhandle)
? ? ? ? self.__clickhandle = self.__renderhandle
? ? else:
? ? ? ? self.__clickhandle = self.__handle
? ? # self.__subhandle = win32gui.FindWindowEx(self.__renderhandle, 0, "subWin", "sub")
? ? # print(self.__subhandle)
? ? # self.__subsubhandle = win32gui.FindWindowEx(self.__subhandle, 0, "subWin", "sub")
? ? # print(self.__subsubhandle)
? ? # win32gui.ShowWindow(hwnd1, win32con.SW_RESTORE)
? ? # print(win32gui.GetWindowRect(hwnd1))
? ? win32gui.SetWindowPos(self.__handle, win32con.HWND_TOP, x_coor, y_coor, 0, 0, win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE)
? ? print(self.__clickhandle)
? ? return self.__handle

獲得后臺(tái)窗口截圖

窗口上方有39個(gè)像素的邊框,左、右、下則有8個(gè)像素的邊框

def get_src(self):
? ? """
? ? @description : 獲得后臺(tái)窗口截圖
? ? ---------
? ? @param : None
? ? -------
? ? @Returns : None
? ? -------
? ? """

? ? left, top, right, bot = win32gui.GetWindowRect(self.__handle)
? ? #Remove border around window (8 pixels on each side)
? ? bl = 8
? ? #Remove border on top
? ? bt = 39

? ? width = int((right - left + 1) * scale) - 2 * bl
? ? height = int((bot - top + 1) * scale) - bt - bl
? ? # 返回句柄窗口的設(shè)備環(huán)境,覆蓋整個(gè)窗口,包括非客戶區(qū),標(biāo)題欄,菜單,邊框
? ? hWndDC = win32gui.GetWindowDC(self.__handle)
? ? # 創(chuàng)建設(shè)備描述表
? ? mfcDC = win32ui.CreateDCFromHandle(hWndDC)
? ? # 創(chuàng)建內(nèi)存設(shè)備描述表
? ? saveDC = mfcDC.CreateCompatibleDC()
? ? # 創(chuàng)建位圖對(duì)象準(zhǔn)備保存圖片
? ? saveBitMap = win32ui.CreateBitmap()
? ? # 為bitmap開辟存儲(chǔ)空間
? ? saveBitMap.CreateCompatibleBitmap(mfcDC, width, height)
? ? # 將截圖保存到saveBitMap中
? ? saveDC.SelectObject(saveBitMap)
? ? # 保存bitmap到內(nèi)存設(shè)備描述表
? ? saveDC.BitBlt((0, 0), (width, height), mfcDC, (bl, bt), win32con.SRCCOPY)
? ? ###獲取位圖信息
? ? bmpinfo = saveBitMap.GetInfo()
? ? bmpstr = saveBitMap.GetBitmapBits(True)
? ? ###生成圖像
? ? im_PIL = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
? ? # 內(nèi)存釋放
? ? win32gui.DeleteObject(saveBitMap.GetHandle())
? ? saveDC.DeleteDC()
? ? mfcDC.DeleteDC()
? ? win32gui.ReleaseDC(self.__handle, hWndDC)
? ? ###PrintWindow成功,保存到文件,顯示到屏幕
? ? im_PIL.save("src.jpg") ?# 保存
? ? # im_PIL.show() ?# 顯示

數(shù)字識(shí)別

依賴項(xiàng)——Tesseract OCR
下載并添加至系統(tǒng)環(huán)境變量

注意:這里將ocr識(shí)別范圍限定為0-9的數(shù)字以提高準(zhǔn)確率
截取范圍為src.jpg中左上(x1,y1)到右下(x2,y2)的矩形區(qū)域

def get_num(self, x1, y1, x2, y2):
? ? """
? ? @description : 獲取屏幕截圖中的數(shù)字
? ? ---------
? ? @param : 截圖中需要截取的含數(shù)字部分邊界
? ? -------
? ? @Returns : num:int
? ? -------
? ? """
? ? ? ??
? ? img = Image.open("src.jpg")
? ? num_img = img.crop((x1, y1, x2, y2))
? ? num_img = ImageOps.invert(num_img)
? ? num = pytesseract.image_to_string(num_img, lang="eng",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? config='--psm 6 --oem 3 -c tessedit_char_whitelist=0123456789').strip()
? ? # num = pytesseract.image_to_string(num_img, lang="eng")
? ? try:
? ? ? ? print("數(shù)量為", int(num))
? ? ? ? return int(num)
? ? except:
? ? ? ? print("未檢測(cè)到數(shù)字")
? ? ? ? return 0

識(shí)別并點(diǎn)擊圖片位置

所需識(shí)別的圖片模板事先準(zhǔn)備好并放在同一目錄下,輸入圖片文件路徑
這里confidence設(shè)置為0.9

def mouse_click_image(self, name : str, times = 0.5):
? ? """
? ? @Description : 鼠標(biāo)左鍵點(diǎn)擊識(shí)別到的圖片位置
? ? ---------
? ? @Args : name:輸入圖片名; times:單擊后延時(shí)
? ? -------
? ? @Returns : None
? ? -------
? ? """
? ? try:
? ? ? ? result = self.recognize(name)
? ? ? ? if result is None or result['confidence'] < 0.9:
? ? ? ? ? ? print("No results!")
? ? ? ? else:
? ? ? ? ? ? print(result['result'][0] + x_coor * scale + 8, " ",result['result'][1] + y_coor * scale + 39)
? ? ? ? ? ? self.mouse_click(result['result'][0] + x_coor * scale + 8, result['result'][1] + y_coor * scale + 39)
? ? except:
? ? ? ? raise Exception("error")

后臺(tái)文字輸入

def type_str(self, msg: str):
    """
    @Description : 打字
    ---------
    @Args : msg:目標(biāo)字符
    -------
    @Returns : None
    -------
    """
    for i in msg:
        self.__PostMessageW(self.__handle, win32con.WM_CHAR, ord(i), 0)

完整代碼

GITEE網(wǎng)址: 項(xiàng)目-AutoClick.

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   AutoClick.py
@Time    :   2021/10/09 15:10:01
@Author  :   Yaadon 
'''

# here put the import lib
import win32con
import win32gui
import win32ui
import time
# import threading
import numpy as np
import os
from PIL import Image
from PIL import ImageOps
import aircv as ac
import pytesseract
from ctypes import windll, byref
from ctypes.wintypes import HWND, POINT
import string
# import sys
# import cv2
# from memory_pic import *
# import win32api
# import autopy
# from PIL import ImageGrab

scale = 1.25 # 電腦的縮放比例
radius = 5 # 隨機(jī)半徑
x_coor = 10 # 窗口位置
y_coor = 10 # 窗口位置

class AutoClick():
    """
    @description  :自動(dòng)點(diǎn)擊類,包含后臺(tái)截圖、圖像匹配
    ---------
    @param  :
    -------
    @Returns  :
    -------
    """
    
    __PostMessageW = windll.user32.PostMessageW
    __SendMessageW = windll.user32.SendMessageW
    __MapVirtualKeyW = windll.user32.MapVirtualKeyW
    __VkKeyScanA = windll.user32.VkKeyScanA
    __ClientToScreen = windll.user32.ClientToScreen

    __WM_KEYDOWN = 0x100
    __WM_KEYUP = 0x101
    __WM_MOUSEMOVE = 0x0200
    __WM_LBUTTONDOWN = 0x0201
    __WM_LBUTTONUP = 0x202
    __WM_MOUSEWHEEL = 0x020A
    __WHEEL_DELTA = 120
    __WM_SETCURSOR = 0x20
    __WM_MOUSEACTIVATE = 0x21

    __HTCLIENT = 1
    __MA_ACTIVATE = 1

    __VkCode = {
        "back":  0x08,
        "tab":  0x09,
        "return":  0x0D,
        "shift":  0x10,
        "control":  0x11,
        "menu":  0x12,
        "pause":  0x13,
        "capital":  0x14,
        "escape":  0x1B,
        "space":  0x20,
        "end":  0x23,
        "home":  0x24,
        "left":  0x25,
        "up":  0x26,
        "right":  0x27,
        "down":  0x28,
        "print":  0x2A,
        "snapshot":  0x2C,
        "insert":  0x2D,
        "delete":  0x2E,
        "lwin":  0x5B,
        "rwin":  0x5C,
        "numpad0":  0x60,
        "numpad1":  0x61,
        "numpad2":  0x62,
        "numpad3":  0x63,
        "numpad4":  0x64,
        "numpad5":  0x65,
        "numpad6":  0x66,
        "numpad7":  0x67,
        "numpad8":  0x68,
        "numpad9":  0x69,
        "multiply":  0x6A,
        "add":  0x6B,
        "separator":  0x6C,
        "subtract":  0x6D,
        "decimal":  0x6E,
        "divide":  0x6F,
        "f1":  0x70,
        "f2":  0x71,
        "f3":  0x72,
        "f4":  0x73,
        "f5":  0x74,
        "f6":  0x75,
        "f7":  0x76,
        "f8":  0x77,
        "f9":  0x78,
        "f10":  0x79,
        "f11":  0x7A,
        "f12":  0x7B,
        "numlock":  0x90,
        "scroll":  0x91,
        "lshift":  0xA0,
        "rshift":  0xA1,
        "lcontrol":  0xA2,
        "rcontrol":  0xA3,
        "lmenu":  0xA4,
        "rmenu":  0XA5
    }

    def __get_virtual_keycode(self, key: str):
        """根據(jù)按鍵名獲取虛擬按鍵碼

        Args:
            key (str): 按鍵名

        Returns:
            int: 虛擬按鍵碼
        """
        if len(key) == 1 and key in string.printable:
            # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-vkkeyscana
            return self.__VkKeyScanA(ord(key)) & 0xff
        else:
            return self.__VkCode[key]


    def __key_down(self, handle: HWND, key: str):
        """按下指定按鍵

        Args:
            handle (HWND): 窗口句柄
            key (str): 按鍵名
        """
        vk_code = self.__get_virtual_keycode(key)
        scan_code = self.__MapVirtualKeyW(vk_code, 0)
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keydown
        wparam = vk_code
        lparam = (scan_code << 16) | 1
        self.__PostMessageW(handle, self.__WM_KEYDOWN, wparam, lparam)


    def __key_up(self, handle: HWND, key: str):
        """放開指定按鍵

        Args:
            handle (HWND): 窗口句柄
            key (str): 按鍵名
        """
        vk_code = self.__get_virtual_keycode(key)
        scan_code = self.__MapVirtualKeyW(vk_code, 0)
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keyup
        wparam = vk_code
        lparam = (scan_code << 16) | 0XC0000001
        self.__PostMessageW(handle, self.__WM_KEYUP, wparam, lparam)


    def __activate_mouse(self, handle: HWND):
        """
        @Description : 激活窗口接受鼠標(biāo)消息
        ---------
        @Args : handle (HWND): 窗口句柄
        -------
        @Returns : 
        -------
        """
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mouseactivate
        lparam = (self.__WM_LBUTTONDOWN << 16) | self.__HTCLIENT
        self.__SendMessageW(handle, self.__WM_MOUSEACTIVATE, self.__handle, lparam)
    

    def __set_cursor(self, handle: HWND, msg):
        """
        @Description : Sent to a window if the mouse causes the cursor to move within a window and mouse input is not captured
        ---------
        @Args : handle (HWND): 窗口句柄, msg : setcursor消息
        -------
        @Returns : 
        -------
        """
        # https://docs.microsoft.com/en-us/windows/win32/menurc/wm-setcursor
        lparam = (msg << 16) | self.__HTCLIENT
        self.__SendMessageW(handle, self.__WM_SETCURSOR, handle, lparam)

    
    def __move_to(self, handle: HWND, x: int, y: int):
        """移動(dòng)鼠標(biāo)到坐標(biāo)(x, y)

        Args:
            handle (HWND): 窗口句柄
            x (int): 橫坐標(biāo)
            y (int): 縱坐標(biāo)
        """
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousemove
        wparam = 0
        lparam = y << 16 | x
        self.__PostMessageW(handle, self.__WM_MOUSEMOVE, wparam, lparam)


    def __left_down(self, handle: HWND, x: int, y: int):
        """在坐標(biāo)(x, y)按下鼠標(biāo)左鍵

        Args:
            handle (HWND): 窗口句柄
            x (int): 橫坐標(biāo)
            y (int): 縱坐標(biāo)
        """
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttondown
        wparam = 0x001 # MK_LBUTTON
        lparam = y << 16 | x
        self.__PostMessageW(handle, self.__WM_LBUTTONDOWN, wparam, lparam)


    def __left_up(self, handle: HWND, x: int, y: int):
        """在坐標(biāo)(x, y)放開鼠標(biāo)左鍵

        Args:
            handle (HWND): 窗口句柄
            x (int): 橫坐標(biāo)
            y (int): 縱坐標(biāo)
        """
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttonup
        wparam = 0
        lparam = y << 16 | x
        self.__PostMessageW(handle, self.__WM_LBUTTONUP, wparam, lparam)


    def __scroll(self, handle: HWND, delta: int, x: int, y: int):
        """在坐標(biāo)(x, y)滾動(dòng)鼠標(biāo)滾輪

        Args:
            handle (HWND): 窗口句柄
            delta (int): 為正向上滾動(dòng),為負(fù)向下滾動(dòng)
            x (int): 橫坐標(biāo)
            y (int): 縱坐標(biāo)
        """
        self.__move_to(handle, x, y)
        # https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel
        wparam = delta << 16
        p = POINT(x, y)
        self.__ClientToScreen(handle, byref(p))
        lparam = p.y << 16 | p.x
        self.__PostMessageW(handle, self.__WM_MOUSEWHEEL, wparam, lparam)


    def __scroll_up(self, handle: HWND, x: int, y: int):
        """在坐標(biāo)(x, y)向上滾動(dòng)鼠標(biāo)滾輪

        Args:
            handle (HWND): 窗口句柄
            x (int): 橫坐標(biāo)
            y (int): 縱坐標(biāo)
        """
        self.__scroll(handle, self.__WHEEL_DELTA, x, y)


    def __scroll_down(self, handle: HWND, x: int, y: int):
        """在坐標(biāo)(x, y)向下滾動(dòng)鼠標(biāo)滾輪

        Args:
            handle (HWND): 窗口句柄
            x (int): 橫坐標(biāo)
            y (int): 縱坐標(biāo)
        """
        self.__scroll(handle, -self.__WHEEL_DELTA, x, y)


    def get_winds(self, title: str):
        """
        @description : 獲取游戲句柄 ,并把游戲窗口置頂并激活窗口
        ---------
        @param : 窗口名
        -------
        @Returns : 窗口句柄
        -------
        """
        # self.__handle = win32gui.FindWindowEx(0, 0, "Qt5QWindowIcon", "MuMu模擬器")
        self.__handle = windll.user32.FindWindowW(None, title)
        self.__classname = win32gui.GetClassName(self.__handle)
        # print(self.__classname)
        if self.__classname == 'Qt5QWindowIcon':
            self.__mainhandle = win32gui.FindWindowEx(self.__handle, 0, "Qt5QWindowIcon", "MainWindowWindow")
            # print(self.__mainhandle)
            self.__centerhandle = win32gui.FindWindowEx(self.__mainhandle, 0, "Qt5QWindowIcon", "CenterWidgetWindow")
            # print(self.__centerhandle)
            self.__renderhandle = win32gui.FindWindowEx(self.__centerhandle, 0, "Qt5QWindowIcon", "RenderWindowWindow")
            # print(self.__renderhandle)
            self.__clickhandle = self.__renderhandle
        else:
            self.__clickhandle = self.__handle
        # self.__subhandle = win32gui.FindWindowEx(self.__renderhandle, 0, "subWin", "sub")
        # print(self.__subhandle)
        # self.__subsubhandle = win32gui.FindWindowEx(self.__subhandle, 0, "subWin", "sub")
        # print(self.__subsubhandle)
        # win32gui.ShowWindow(hwnd1, win32con.SW_RESTORE)
        # print(win32gui.GetWindowRect(hwnd1))
        win32gui.SetWindowPos(self.__handle, win32con.HWND_TOP, x_coor, y_coor, 0, 0, win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE)
        print(self.__clickhandle)
        return self.__handle
    

    def get_src(self):
        """
        @description : 獲得后臺(tái)窗口截圖
        ---------
        @param : None
        -------
        @Returns : None
        -------
        """

        left, top, right, bot = win32gui.GetWindowRect(self.__handle)
        #Remove border around window (8 pixels on each side)
        bl = 8
        #Remove border on top
        bt = 39

        width = int((right - left + 1) * scale) - 2 * bl
        height = int((bot - top + 1) * scale) - bt - bl
        # 返回句柄窗口的設(shè)備環(huán)境,覆蓋整個(gè)窗口,包括非客戶區(qū),標(biāo)題欄,菜單,邊框
        hWndDC = win32gui.GetWindowDC(self.__handle)
        # 創(chuàng)建設(shè)備描述表
        mfcDC = win32ui.CreateDCFromHandle(hWndDC)
        # 創(chuàng)建內(nèi)存設(shè)備描述表
        saveDC = mfcDC.CreateCompatibleDC()
        # 創(chuàng)建位圖對(duì)象準(zhǔn)備保存圖片
        saveBitMap = win32ui.CreateBitmap()
        # 為bitmap開辟存儲(chǔ)空間
        saveBitMap.CreateCompatibleBitmap(mfcDC, width, height)
        # 將截圖保存到saveBitMap中
        saveDC.SelectObject(saveBitMap)
        # 保存bitmap到內(nèi)存設(shè)備描述表
        saveDC.BitBlt((0, 0), (width, height), mfcDC, (bl, bt), win32con.SRCCOPY)
        ###獲取位圖信息
        bmpinfo = saveBitMap.GetInfo()
        bmpstr = saveBitMap.GetBitmapBits(True)
        ###生成圖像
        im_PIL = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
        # 內(nèi)存釋放
        win32gui.DeleteObject(saveBitMap.GetHandle())
        saveDC.DeleteDC()
        mfcDC.DeleteDC()
        win32gui.ReleaseDC(self.__handle, hWndDC)
        ###PrintWindow成功,保存到文件,顯示到屏幕
        im_PIL.save("src.jpg")  # 保存
        # im_PIL.show()  # 顯示
    

    
    

    def recognize(self, objs):
        """
        @description : 圖像識(shí)別之模板匹配
        ---------
        @param : 需要匹配的模板名
        -------
        @Returns : 將傳進(jìn)來的圖片和全屏截圖匹配如果找到就返回圖像在屏幕的坐標(biāo) 否則返回None
        -------
        """
        
        imobj = ac.imread(objs)
        imsrc = ac.imread('%s\\src.jpg' % os.getcwd())
        pos = ac.find_template(imsrc, imobj, 0.5)
        return pos


    def mouse_click(self, x, y, times=0.5):
        """
        @description : 單擊左鍵
        ---------
        @param : 位置坐標(biāo)x,y 單擊后延時(shí)times(s)
        -------
        @Returns : 
        -------
        """
        # self.__set_cursor(self.__clickhandle, self.__WM_MOUSEACTIVATE)
        # self.__move_to(self.__clickhandle, int(x / scale), int(y / scale))
        # self.__activate_mouse(self.__clickhandle)
        # self.__set_cursor(self.__clickhandle, self.__WM_LBUTTONDOWN)
        self.__left_down(self.__clickhandle, int(x / scale), int(y / scale))
        self.__move_to(self.__clickhandle, int(x / scale), int(y / scale))
        self.__left_up(self.__clickhandle, int(x / scale), int(y / scale))
        time.sleep(times)
    

    def mouse_click_image(self, name : str, times = 0.5):
        """
        @Description : 鼠標(biāo)左鍵點(diǎn)擊識(shí)別到的圖片位置
        ---------
        @Args : name:輸入圖片名; times:單擊后延時(shí)
        -------
        @Returns : None
        -------
        """
        try:
            result = self.recognize(name)
            if result is None or result['confidence'] < 0.9:
                print("No results!")
            else:
                print(result['result'][0] + x_coor * scale + 8, " ",result['result'][1] + y_coor * scale + 39)
                self.mouse_click(result['result'][0] + x_coor * scale + 8, result['result'][1] + y_coor * scale + 39)
        except:
            raise Exception("error")

    
    def mouse_click_radius(self, x, y, times=0.5):
        """
        @description : 在范圍內(nèi)隨機(jī)位置單擊(防檢測(cè))
        ---------
        @param : 位置坐標(biāo)x,y 單擊后延時(shí)times(s)
        -------
        @Returns : 
        -------
        """
        
        random_x = np.random.randint(-radius, radius)
        random_y = np.random.randint(-radius, radius)
        self.mouse_click(x + random_x, y + random_y)
        # self.__left_down(self.__clickhandle, int((x + random_x) / scale), int((y + random_y) / scale))
        # time.sleep(0.1)
        # self.__left_up(self.__clickhandle, int((x + random_x) / scale), int((y + random_y) / scale))
        time.sleep(times)


    def push_key(self, key: str, times = 1):
        """
        @Description : 按鍵
        ---------
        @Args : key:按鍵 times:按下改鍵后距松開的延時(shí)
        -------
        @Returns : None
        -------
        """
        self.__key_down(self.__clickhandle, key)
        time.sleep(times)
        self.__key_up(self.__clickhandle, key)
        time.sleep(0.5)
    

    def type_str(self, msg: str):
        """
        @Description : 打字
        ---------
        @Args : msg:目標(biāo)字符
        -------
        @Returns : None
        -------
        """
        for i in msg:
            self.__PostMessageW(self.__clickhandle, win32con.WM_CHAR, ord(i), 0)


if __name__ == '__main__':
    click = AutoClick()
    click.get_winds("微信")
    click.get_src()
    # click.mouse_click(254, 536)
    click.mouse_click_image('test.png')
    # click.mouse_click(1086, 269) # 輸入框
    # click.mouse_click(237, 211) # 輸入框
    # click.mouse_click(1228, 201) # 輸入框
    # click.type_str("123木頭人abc")

參考

部分參考自: Python開發(fā)游戲自動(dòng)化腳本(四)后臺(tái)鍵鼠操作.

到此這篇關(guān)于Python開發(fā)游戲自動(dòng)化后臺(tái)腳本的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Python 游戲自動(dòng)化后臺(tái)腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

肥乡县| 乌鲁木齐县| 光山县| 资阳市| 奉节县| 东兴市| 宁武县| 岳阳县| 和平县| 叙永县| 达日县| 上犹县| 寻乌县| 凤城市| 克什克腾旗| 玛沁县| 娄底市| 阿坝| 纳雍县| 屏山县| 德惠市| 满洲里市| 江油市| 于田县| 淄博市| 吐鲁番市| 乐至县| 界首市| 太保市| 西安市| 华宁县| 吉木萨尔县| 礼泉县| 汉源县| 华容县| 于都县| 大竹县| 中方县| 霍林郭勒市| 稻城县| 东辽县|