0

我正在尝试创建一个玩 CS:GO 的 AI。

但我无法移动目标。

我尝试了 pyautogui、win32api、pynput 库,它们都可以在桌面或任何有光标的地方工作。

但是在游戏中没有光标,当我跟随鼠标的位置时,鼠标的位置停留在中间((1920/2,1080/2),对我来说)当移动鼠标转动它会增加一小段时间然后回到那个位置。

如何通过 python 在 CS:GO 或 GTA 5 或任何游戏中移动目标。python代码和真正的鼠标有什么区别?

我不认为这是因为反作弊,因为它不适用于 GTA 5

我看了同样的话题,但他们没有解决我的问题

所有库的代码都相似,所以我使用的代码是这样的:

import pyautogui, sys
import _thread
import time

time.sleep(2)

def kaydir(miktarX, miktarY):
    pyautogui.moveRel(miktarX, miktarY)

print('Press Ctrl-C to quit.')
try:
    while True:
        x, y = pyautogui.position()
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
        print(positionStr, end='')
        print('\b' * len(positionStr), end='', flush=True)
        _thread.start_new_thread(kaydir, (1, 1))
        time.sleep(0.08)
except KeyboardInterrupt:
    print('\n')
4

1 回答 1

1

So first thing is: What do you mean with that question:

what is the difference between python code and real mouse?

But if you want to create an bot for any game you have 2 options:

  • Memory Hacking: Get some memory pointers to change input flags etc (via CheatEngine etc)

  • Simulating user interaction (your way): If you want to use PyAutoGUI for interaction i think this is a good point to start: https://www.youtube.com/watch?v=NaZTtUmE990

    Another way, I would prefer, is (as you have mentioned) the WinAPI: C++ implementation for mouse moving (since i dont know how to do it in python):

    int main() {
        HWND tWin= FindWindow("TargetWindow", "Target Window");
        if (tWin) {
            RECT rect = {0};
            GetWindowRect(tWin, &rect);
            SetCursorPos(rect.right - 180 /*x offset*/, rect.bottom - 300 /*y offset*/);
        }
    
        return 0;
    }
    

    Also make sure that if your program is 64-bit use the 64-bit WinAPI.

    If your game is running under higher privilegies as you bot you need to run your bot as Administrator or as SYSTEM

    But I think to create a bot you also need memory hacking (just reading) for getting the player position etc, Since how do you extract pos items etc from the gamescreen-imgage from the programmers point of view?. You may also can also use Machine Learning but for a game it needs a huge training process.

于 2020-05-15T19:03:11.437 回答