尝试使用python控制游戏

问题描述 投票:0回答:1

[我正在尝试将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")
python python-3.x keypress simulate
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.