Python的一键宏游戏
问题描述:
这是我的Python 2.7.13
脚本,基本上是所谓的视频游戏的“一键宏”。基于从游戏屏幕的一部分获取的信息,它按下正确的按键组合而不是玩家。所以玩家发送了f
密钥,脚本按下其他键f
。Python的一键宏游戏
它正在工作,但在随机时间(开始后1-5分钟)脚本停止或类似的事情。我可以在Windows任务管理器中看到脚本正在运行,但是当我按下f
键时没有任何反应。
在开始时,我写了一些更多未优化的代码,它多次使用屏幕截图/按键。当时脚本“冻结”更多。
这可能是因为太多的屏幕截图吗?还是我在某个地方搞砸了?
import pyautogui, pythoncom, pyHook
# Determine if an ability is ready or not
def ready(x,y, im):
if (im.getpixel((x,y)) != (0,0,0)):
return True
else:
return False
def ability1(im):
return (ready(17, 16, im) or ready(35, 16, im))
def ability2(im):
return ready(134, 9, im)
# Listen for keypress
def OnKeyboardEvent(event):
im = pyautogui.screenshot(region=(249, 770, 194, 26))
if (event.KeyID == 70): # Pressed the "f" key
if (ability1(im)):
pyautogui.hotkey('shift','4')
return True
if (ability2(im)):
pyautogui.press('-')
return True
pyautogui.press('1')
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
答
如果你在运行服务器上运行它,这可能是由于增加了对Warden的检查/干扰。
我建议不要在现场服务器上使用这种自动化,如果注意到可能会导致禁止。