0

我正在尝试将 Python 与 win32api 一起使用来控制游戏(Maplestory)。我的脚本可以在很多软件(如记事本)上完美运行,但游戏除外。

我想也许游戏直接与硬件通信,所以我不能使用 win32api 来控制游戏。但我不知道如何使用 Python 脚本与硬件进行通信。而且我也不知道谁写了一个可以与键盘硬件通信的轮子。

这是我的脚本:

import time,random,win32con,win32api

WAIT_TIME = 5

key_map = {
    "0": 49, "1": 50, "2": 51, "3": 52, "4": 53, "5": 54, "6": 55, "7": 56, "8": 57, "9": 58,
    "A": 65, "B": 66, "C": 67, "D": 68, "E": 69, "F": 70, "G": 71, "H": 72, "I": 73, "J": 74,
    "K": 75, "L": 76, "M": 77, "N": 78, "O": 79, "P": 80, "Q": 81, "R": 82, "S": 83, "T": 84,
    "U": 85, "V": 86, "W": 87, "X": 88, "Y": 89, "Z": 90
}

class Press:
    def __init__(self):
        print("The program will start in %d seconds" % WAIT_TIME)
        time.sleep(WAIT_TIME)
        self.time = time.time()
        pass

    def key_down(self, key):
        key = key.upper()
        vk_code = key_map[key]
        win32api.keybd_event(vk_code,win32api.MapVirtualKey(vk_code,0),0,0)


    def key_up(self, key):
        key = key.upper()
        vk_code = key_map[key]
        win32api.keybd_event(vk_code, win32api.MapVirtualKey(vk_code, 0), win32con.KEYEVENTF_KEYUP, 0)


    def key_press(self, key):
        self.key_down(key)
        time.sleep(0.02)
        self.key_up(key)
        print(key)



class Illium(Press):
    def __init__(self):
        super().__init__()
        self.spear = "A"
        self.bullet = "Q"
        self.buff1 = "3"
        self.buff2 = "4"

    def add_buff(self):
        if time.time() - self.time > 60:
            self.key_press(self.buff1)
            time.sleep(0.5)
            self.key_press(self.buff2)
            time.sleep(random.uniform(0.5,1))
            self.key_press("1")   # 
            self.time = time.time()

    def auto_attack(self):
        self.add_buff()
        time.sleep(random.uniform(0.5,1))  
        self.key_press(self.spear)
        time.sleep(random.uniform(1,1.5))
        self.key_press(self.bullet)
        time.sleep(random.uniform(0.5,1))




illium = Illium()
while True:
    illium.auto_attack()
    time.sleep(random.uniform(0.5,1))


print("ENd")
4

1 回答 1

0

有些游戏会采取一些措施来阻止脚本运行(防止作弊)。也许使用 python 脚本不是一个好主意。

我不玩这个游戏。如果你真的想使用python,也许你可以尝试其他模块来控制游戏(如pynput,pykeyboard等)。

于 2019-12-29T06:44:37.683 回答