使用Python将密钥发送到gam中

2024-10-03 17:23:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python很陌生,但确实有其他语言的经验。我最近在steam上买了个人电脑版的《最终幻想3》,我想测试一下我一周前的python技能,看看我是否可以自动将按键发送到游戏中,以便在我不在的时候为我玩游戏,磨练我的工作水平。在

在互联网上快速搜索,我找到了这个http://win32com.goermezer.de/content/view/136/254/,我希望它能让我做到这一点。在

我的代码是:

import win32com.client
import time

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Final Fantasy III")

def actionSelect():
    time.sleep(1) #time between switching characters
    shell.SendKeys("s", 0) #'s' is my down key
    time.sleep(0.2)
    shell.SendKeys("s", 0)
    # so it goes down two options for each character for the 'Guard' option
    time.sleep(0.2) #slight delay between each key to compensate for processing
    shell.SendKeys("e", 0) #then it uses the 'e' key to select that option
    return

def battle():
    time.sleep(5)
    for rounds in range(0, 10): #loops 10 times (due to xp gain per action) 
        for action in range(0, 4): #loops 4 times = 4 charcaters
            actionSelect()
        time.sleep(9) #time for all to Guard and enemy to attack

battle()

我不知道第三行和第四行代码做了什么,用外行的话说,谷歌搜索和扫描的数量不多。我也不确定SendKeys(“s”,0)中的0是做什么的。代码本身起作用。。。但我只在任何文本框中单击。它没有像我计划的那样切换到游戏窗口(我该怎么做?)如果我手动切换到游戏中,它会一直在后台运行,但实际上不会控制游戏中的任何东西。在

任何对我的“乐趣”周末项目的帮助都将非常感激。谢谢。在


Tags: tokey代码importclient游戏fortime
1条回答
网友
1楼 · 发布于 2024-10-03 17:23:53

您可以使用我对this问题的回答向其他应用程序发送击键。它在Playerunknown的战场(PUBG)中对我起了作用,它运行在虚幻引擎4中,所以我想象使用这个引擎的其他游戏和其他许多游戏应该能够接收来自该方法的输入

相关问题 更多 >